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

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


秒の頻度でTimeDeltaIndexに対してceil操作を実行するには、 TimeDeltaIndex.ceil()を使用します。 方法。秒の頻度については、頻度を使用します 値が「S」のパラメータ 。

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

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操作。秒の頻度については、「S」-

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

以下はコードです-

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

出力

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

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 seconds frequency...
TimedeltaIndex(['4 days 08:20:01', '0 days 17:42:20', '9 days 11:16:03',
'0 days 22:35:26'],
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を使用して秒の周波数分解能を設定します 値が‘s’のパラメータ 。 まず、必要なライブラリをインポートします- import pandas as pd Timedeltaオブジェクトを作成する- timedelta = pd.Timedelta('1 days 11 hours 22 min 25 s 50 ms 45 ns') タイムデルタを表示- print("Timedelta...\n", timedelta) 秒の頻度で丸