要检查 BusinessDay Offset 是否已标准化,请使用BusinessDay.normalizePandas 中的属性。
首先,导入所需的库 -
import datetime import pandas as pd
在 Pandas 中设置时间戳对象 -
timestamp = pd.Timestamp('2021-10-30 01:55:02.000045')
创建工作日偏移量。BusinessDay 是 DateOffset 子类。我们使用“normalize”参数标准化了工作日 -
bdOffset = pd.tseries.offsets.BusinessDay(offset = datetime.timedelta(hours = 8, minutes = 10), normalize=True)
显示更新的时间戳 -
print("\nUpdated Timestamp...\n",timestamp + bdOffset)
检查 BusinessDay Offset 是否标准化 -
print("\nThe BusinessDay Offset is normalized..\n", bdOffset.normalize)
以下是代码 -
import datetime import pandas as pd # 在 Pandas 中设置时间戳对象 timestamp = pd.Timestamp('2021-10-30 01:55:02.000045') # 显示时间戳 print("Timestamp...\n",timestamp) # 创建工作日抵消 # BusinessDay 是 DateOffset 子类 # We have normalized the BusinessDay using the "normalize" parameter bdOffset = pd.tseries.offsets.BusinessDay(offset = datetime.timedelta(hours = 8, minutes = 10), normalize=True) # 显示工作日偏移 print("\nBusinessDay Offset...\n",bdOffset) # 显示更新的时间戳 print("\nUpdated Timestamp...\n",timestamp + bdOffset) # 以字符串形式返回应用于给定 BusinessDay 对象的频率 print("\nFrequency on the given BusinessDay Offset...\n",bdOffset.freqstr) # 返回应用于给定 BusinessDay 对象的频率名称 print("\nThe name of the frequency on the BusinessDay object..\n", bdOffset.name) # 检查 BusinessDay Offset 是否标准化 print("\nThe BusinessDay Offset is normalized..\n", bdOffset.normalize)输出结果
这将产生以下代码 -
Timestamp... 2021-10-30 01:55:02.000045 BusinessDay Offset... <BusinessDay: offset=datetime.timedelta(seconds=29400)> Updated Timestamp... 2021-11-01 00:00:00 Frequency on the given BusinessDay Offset... B+8H10Min The name of the frequency on the BusinessDay object.. B The BusinessDay Offset is normalized.. True