PythonPandas-BusinessHourオフセットに適用された増分の数を返します
BusinessHourオフセットに適用された増分のカウントを返すには、PandasのBusinessHour.nプロパティを使用します。
まず、必要なライブラリをインポートします-
import pandas as pd
パンダでタイムスタンプオブジェクトを設定します-
timestamp = pd.Timestamp('2021-1-1 01:55:30') BusinessHourオフセットを作成します。ここで、「開始」は、24時間形式のカスタム営業時間の開始時刻です。 「終了」は、24時間形式のカスタム営業時間の終了時刻です-
bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end = "18:00", n = 8)
更新されたタイムスタンプを表示する-
print("\nUpdated Timestamp...\n",timestamp + bhOffset) 指定されたBusinessHourオブジェクトの増分数を返します-
print("\nThe count of increments on the BusinessHour object..\n", bhOffset.n) 例
以下はコードです-
import pandas as pd
# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-1-1 01:55:30')
# Display the Timestamp
print("Timestamp...\n",timestamp)
# Create the BusinessHour Offset
# BusinessHour is the DateOffset subclass
# Here, "start" is the start time of your custom business hour in 24h format.
# The "end" is the end time of your custom business hour in 24h format.
bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end = "18:00", n = 8)
# Display the BusinessHour Offset
print("\nBusinessHour Offset...\n",bhOffset)
# Display the Updated Timestamp
print("\nUpdated Timestamp...\n",timestamp + bhOffset)
# return the count of increments on the given BusinessHour object
print("\nThe count of increments on the BusinessHour object..\n", bhOffset.n) 出力
これにより、次のコードが生成されます-
Timestamp... 2021-01-01 01:55:30 BusinessHour Offset... <8 * BusinessHours: BH=09:30-18:00> Updated Timestamp... 2021-01-01 17:30:00 The count of increments on the BusinessHour object.. 8
-
PythonPandas-オフセットオブジェクトに適用される頻度の名前を返します
オフセットオブジェクトに適用される頻度の名前を返すには、Pandasのoffset.nameプロパティを使用します。まず、必要なライブラリをインポートします- from pandas.tseries.frequencies import to_offset import pandas as pd パンダでタイムスタンプオブジェクトを設定します- timestamp = pd.Timestamp('2021-09-26 03:25:02.000045') DateOffsetを作成します。ここでは、「M」頻度を使用して月をインクリメントしています- offset = to_
-
PythonPandas-指定されたDateOffsetオブジェクトに適用された頻度を返します
指定されたDateOffsetオブジェクトに適用された頻度を返すには、Pandasでoffset.freqstrを使用します。まず、必要なライブラリをインポートします- from pandas.tseries.frequencies import to_offset import pandas as pd パンダでタイムスタンプオブジェクトを設定します- timestamp = pd.Timestamp('2021-09-26 03:25:02.000045') DateOffsetを作成します。ここでは、「D」頻度を使用して日数を増やしています- offset = to