Python
 Computer >> コンピューター >  >> プログラミング >> Python

PythonPandas-1時間ごとの頻度でTimeDeltaIndexオブジェクトに対してceil操作を実行します


TimeDeltaIndexで1時間ごとの頻度でceil操作を実行するには、 TimeDeltaIndex.ceil()を使用します。 方法。時間ごとの頻度については、頻度を使用してください 値が「H」のパラメータ 。

まず、必要なライブラリをインポートします-

import pandas as pd

TimeDeltaIndexオブジェクトを作成します。 'data'パラメータを使用してtimedeltaのようなデータを設定しました-

tdIndex = pd.TimedeltaIndex(data =['4 day 8h 20min 35us 45ns', '+17:42:19.999999',
'9 day 3h 08:16:02.000055', '+22:35:25.000075'])

TimedeltaIndexを表示-

print("TimedeltaIndex...\n", tdIndex)

TimeDeltaIndexの日付で1時間ごとの頻度でCeil操作を実行します。時間ごとの頻度には、「H」-

を使用しました。
print("\nPerforming Ceil operation with hourly frequency...\n",
tdIndex.ceil(freq='H'))

以下はコードです-

import pandas as pd

# Create a TimeDeltaIndex object
# We have set the timedelta-like data using the 'data' parameter
tdIndex = pd.TimedeltaIndex(data =['4 day 8h 20min 35us 45ns', '+17:42:19.999999',
'9 day 3h 08:16:02.000055', '+22:35:25.000075'])

# display TimedeltaIndex
print("TimedeltaIndex...\n", tdIndex)

# Return a dataframe of the components of TimeDeltas
print("\nThe Dataframe of the components of TimeDeltas...\n", tdIndex.components)

# Ceil operation on TimeDeltaIndex date with hourly frequency
# For hourly frequency, we have used 'H'
print("\nPerforming Ceil operation with hourly frequency...\n",
tdIndex.ceil(freq='H'))

出力

これにより、次のコードが生成されます-

TimedeltaIndex...
TimedeltaIndex(['4 days 08:20:00.000035045', '0 days 17:42:19.999999',
'9 days 11:16:02.000055', '0 days 22:35:25.000075'],
dtype='timedelta64[ns]', freq=None)

The Dataframe of the components of TimeDeltas...
   days hours minutes seconds milliseconds microseconds nanoseconds
0    4     8     20        0         0            35           45
1    0    17     42       19       999           999            0
2    9    11     16        2         0            55            0
3    0    22     35       25         0            75            0

Performing Ceil operation with hourly frequency...
TimedeltaIndex(['4 days 09:00:00', '0 days 18:00:00', '9 days 12:00:00',
'0 days 23:00:00'],
dtype='timedelta64[ns]', freq=None)

  1. PythonPandas-1時間ごとの頻度でDateTimeIndexでフロア操作を実行する方法

    1時間ごとの頻度でDateTimeIndexに対してフロア操作を実行するには、 DateTimeIndex.floor()を使用します。 方法。時間ごとの頻度については、頻度を使用してください 値が「H」のパラメータ 。 まず、必要なライブラリをインポートします- import pandas as pd 期間5、頻度を最小、つまり分としてDatetimeIndexを作成します- datetimeindex = pd.date_range('2021-09-29 07:20:32.261811624', periods=5, tz='Australia/Adelaid

  2. Pythonパンダ-1時間ごとの頻度でTimedeltaを丸める

    指定された解像度でTimedeltaを丸めるには、 timestamp.round()を使用します 方法。値Hのfreqパラメータを使用して、1時間ごとの周波数分解能を設定します。 まず、必要なライブラリをインポートします- import pandas as pd TimeDeltasは、Pythonの標準の日時ライブラリであり、異なる表現のtimedeltaを使用します。 Timedeltaオブジェクトを作成する timedelta = pd.Timedelta('2 days 10 hours 45 min 20 s 35 ms 55 ns') タイムデルタを表示する