PythonPandas-指定されたCustomBusinessDayオブジェクトに適用されたキーワード引数を表示します
指定されたCustomBusinessDayオブジェクトに適用されたキーワード引数を表示するには、PandasのCustomBusinessDay.kwdsプロパティを使用します。
まず、必要なライブラリをインポートします-
import pandas as pd
パンダでタイムスタンプオブジェクトを設定します-
timestamp = pd.Timestamp('2021-12-31 08:35:10')
CustomBusinessDayオフセットを作成する-
cbdOffset = pd.tseries.offsets.CustomBusinessDay(n = 2, weekmask = 'Mon Tue Wed Fri')
タイムスタンプにオフセットを追加し、更新されたタイムスタンプを表示します-
print("\nUpdated Timestamp...\n",timestamp + cbdOffset)
キーワード引数を表示する-
print("\nKeyword arguments on the given CustomBusinessDay Offset...\n",cbdOffset.kwds) 例
以下はコードです-
import pandas as pd
# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-12-31 08:35:10')
# 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 = 2, 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)
# Display the keyword arguments
print("\nKeyword arguments on the given CustomBusinessDay Offset...\n",cbdOffset.kwds) 出力
これにより、次のコードが生成されます-
Timestamp...
2021-12-31 08:35:10
CustomBusinessDay Offset...
<2 * CustomBusinessDays>
Updated Timestamp...
2022-01-04 08:35:10
Frequency applied on the given CustomBusinessDay Offset object...
2C
Keyword arguments on the given CustomBusinessDay Offset...
{'weekmask': 'Mon Tue Wed Fri', 'holidays': (), 'calendar': <numpy.busdaycalendar object at 0x00000134D22E5FC0>, 'offset': datetime.timedelta(0)} -
PythonPandas-指定されたDateOffsetオブジェクトのナノ秒数を返します
指定されたDateOffsetオブジェクトのナノ秒数を返すには、Pandasのoffset.nanosプロパティを使用します。 まず、必要なライブラリをインポートします- from pandas.tseries.frequencies import to_offset import pandas as pd パンダでタイムスタンプオブジェクトを設定します- timestamp = pd.Timestamp('2021-08-30 03:08:02.000045') DateOffsetを作成します。ここでは、「D」頻度を使用して日数を増やしています- offset =
-
PythonPandas-指定されたDateOffsetオブジェクトに適用される頻度を文字列として返します
指定されたDateOffsetオブジェクトに適用された頻度を文字列として返すには、 offset.freqstrを使用します パンダのプロパティ。 まず、必要なライブラリをインポートします- from pandas.tseries.offsets import DateOffset import pandas as pd パンダでタイムスタンプオブジェクトを設定します- timestamp = pd.Timestamp('2021-08-30 02:30:55') DateOffsetを作成します。ここでは、「months」パラメータを使用して月をインクリメントしていま