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

PythonPandas-TimeDeltaIndexオブジェクトに対して分単位の頻度でceil操作を実行します


微小な頻度でTimeDeltaIndexに対してceil操作を実行するには、 TimeDeltaIndex.ceil()を使用します。 方法。分単位の頻度については、頻度を使用してください 値が‘T’のパラメータ 。

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

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日付のCeil操作。分単位の頻度については、「T」-

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

以下はコードです-

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 minutely frequency
# For minutely frequency, we have used 'T'
print("\nPerforming Ceil operation with minutely frequency...\n",
tdIndex.ceil(freq='T'))

出力

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

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 minutely frequency...
TimedeltaIndex(['4 days 08:21:00', '0 days 17:43:00', '9 days 11:17:00',
'0 days 22:36: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. PythonPandas-タイムデルタを分単位の頻度で丸める

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