PythonPandas-指定されたBusinessHourOffsetオブジェクトに適用される戻り頻度を文字列として
指定されたBusinessHourOffsetオブジェクトに適用された頻度を文字列として返すには、PandasのBusinessHour.freqstrプロパティを使用します。
まず、必要なライブラリをインポートします-
import pandas as pd
パンダでタイムスタンプオブジェクトを設定します-
timestamp = pd.Timestamp('2021-1-1 01:55:30')
BusinessHourオフセットを作成する-
bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end = "18:00")
更新されたタイムスタンプを表示する-
print("\nUpdated Timestamp...\n",timestamp + bhOffset)
指定されたBusinessHourOffsetオブジェクトに文字列として適用される戻り頻度-
print("\nFrequency applied on the given BusinessHour Offset object...\n",bhOffset.freqstr) 例
以下はコードです-
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)> 出力
これにより、次のコードが生成されます-
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
-
PythonPandas-頻度オブジェクトをPeriodIndexオブジェクトから文字列として返します
頻度オブジェクトをPeriodIndexオブジェクトから文字列として返すには、 PeriodIndex.freqstrを使用します プロパティ。 まず、必要なライブラリをインポートします- import pandas as pd PeriodIndexオブジェクトを作成します。 PeriodIndexは、一定期間を示す順序値を保持する不変のndarrayです- periodIndex = pd.PeriodIndex(['2021-09-25 07:50:35', '2019-10-30 04:35:45', '2021-07-15 02:25:15
-
PythonPandas-指定されたPeriodオブジェクトに適用された時系列頻度の文字列エイリアスを返します
指定されたPeriodオブジェクトに適用された時系列頻度の文字列エイリアスを返すには、 period.freqstrを使用します プロパティ。 まず、必要なライブラリをインポートします- import pandas as pd pandas.Periodは期間を表します。 2つのPeriodオブジェクトの作成- period1 = pd.Period("2020-09-23 03:55:20") period2 = pd.Period(freq="Y", year = 2021, month = 2, day = 14, hour = 2, minu