PythonPandas-指定されたBusinessHourオブジェクトに適用されたルールコードを返します
指定されたBusinessHourオブジェクトに適用されたルールコードを返すには、PandasのBusinessHour.rule_codeプロパティを使用します。
まず、必要なライブラリをインポートします-
import pandas as pd
パンダでタイムスタンプオブジェクトを設定します-
timestamp = pd.Timestamp('2021-1-1 01:55:30')
BusinessHourオフセットを作成します。 BusinessHourはDateOffsetサブクラスです-
bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end = "18:00")
更新されたタイムスタンプを表示する-
print("\nUpdated Timestamp...\n",timestamp + bhOffset)
指定されたBusinessHourオフセットに適用される頻度のルールコードを返します-
print("\nThe rule code of the BusinessHour object..\n", bhOffset.rule_code) 例
以下はコードです-
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")
# Display the BusinessHour Offset
print("\nBusinessHour Offset...\n",bhOffset)
# Display the Updated Timestamp
print("\nUpdated Timestamp...\n",timestamp + bhOffset)
# return the rule code of the frequency applied on the given BusinessHour Offset
print("\nThe rule code of the BusinessHour object..\n", bhOffset.rule_code) 出力
これにより、次のコードが生成されます-
Timestamp... 2021-01-01 01:55:30 BusinessHour Offset... <BusinessHour: BH=09:30-18:00> Updated Timestamp... 2021-01-01 10:30:00 The rule code of the BusinessHour object.. BH
-
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」パラメータを使用して月をインクリメントしていま