PythonPandas-指定されたBusinessHourオブジェクトに適用されたキーワード引数を表示します
特定のBusinessHourオブジェクトに適用されたキーワード引数を表示するには、PandasのBusinessHour.kwdsプロパティを使用します。
まず、必要なライブラリをインポートします-
import pandas as pd
BusinessHourオフセットを作成します。ここで、「開始」は、24時間形式のカスタム営業時間の開始時間です。 「終了」は、24時間形式のカスタム営業時間の終了時刻です-
bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end = "18:00")
パンダでタイムスタンプオブジェクトを設定します-
timestamp = pd.Timestamp('2021-1-1 01:55:30') 更新されたタイムスタンプを表示する-
print("\nUpdated Timestamp...\n",timestamp + bhOffset)
キーワード引数を表示する-
print("\nKeyword arguments on the given BusinessHour Offset...\n",bhOffset.kwds) 例
以下はコードです-
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 frequency applied on the given BusinessHour Offset object as a string
print("\nFrequency applied on the given BusinessHour Offset object...\n",bhOffset.freqstr)
# Display the keyword arguments
print("\nKeyword arguments on the given BusinessHour Offset...\n",bhOffset.kwds) 出力
これにより、次のコードが生成されます-
Timestamp...
2021-01-01 01:55:30
BusinessHour Offset...
<BusinessHour: BH=09:30-18:00>
Updated Timestamp...
2021-01-01 10:30:00
Frequency applied on the given BusinessHour Offset object...
BH
Keyword arguments on the given BusinessHour Offset...
{'start': (datetime.time(9, 30),), 'end': (datetime.time(18, 0),), '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」パラメータを使用して月をインクリメントしていま