PythonPandas-CustomBusinessDayオフセットに適用された増分の数を返します
CustomBusinessDayオフセットに適用された増分のカウントを返すには、PandasのCustomBusinessDay.nプロパティを使用します。
まず、必要なライブラリをインポートします-
import pandas as pd
パンダでタイムスタンプオブジェクトを設定します-
timestamp = pd.Timestamp('2021-10-22 03:10:35')
CustomBusinessDayオフセットを作成する-
cbdOffset = pd.tseries.offsets.CustomBusinessDay(n = 4, weekmask = 'Mon Tue Wed Fri')
タイムスタンプにオフセットを追加し、更新されたタイムスタンプを表示します-
print("\nUpdated Timestamp...\n",timestamp + cbdOffset)
指定されたCustomBusinessDayオブジェクトの増分数を返します-
print("\nThe count of increments on the CustomBusinessDay object..\n", cbdOffset.n) 例
以下はコードです-
import pandas as pd
# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-10-22 03:10:35')
# Display the Timestamp
print("Timestamp...\n",timestamp)
# Create the CustomBusinessDay Offset
# CustomBusinessDay is the DateOffset subclass representing custom business days excluding holidays
# Weekmask of valid business days
cbdOffset = pd.tseries.offsets.CustomBusinessDay(n = 4, weekmask = 'Mon Tue Wed Fri')
# Display the CustomBusinessDay Offset
print("\nCustomBusinessDay Offset...\n",cbdOffset)
# Add the offset to the Timestamp and display the Updated Timestamp
print("\nUpdated Timestamp...\n",timestamp + cbdOffset)
# Return frequency applied on the given CustomBusinessDay Offset object as a string
print("\nFrequency applied on the given CustomBusinessDay Offset object...\n",cbdOffset.freqstr)
# return the count of increments on the given CustomBusinessDay object
print("\nThe count of increments on the CustomBusinessDay object..\n", cbdOffset.n) 出力
これにより、次のコードが生成されます-
Timestamp... 2021-10-22 03:10:35 CustomBusinessDay Offset... <4 * CustomBusinessDays> Updated Timestamp... 2021-10-29 03:10:35 Frequency applied on the given CustomBusinessDay Offset object... 4C The count of increments on the CustomBusinessDay object.. 4
-
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