要返回适用于 BusinessDay 偏移量的增量计数,请使用BusinessDay.nPandas 中的属性。
首先,导入所需的库 -
import datetime import pandas as pd
在 Pandas 中设置时间戳对象” -
timestamp = pd.Timestamp('2021-10-30 01:55:02.000045')
创建工作日偏移量。BusinessDay 是 DateOffset 子类 -
bdOffset = pd.tseries.offsets.BusinessDay(n = 6)
显示更新的时间戳 -
print("\nUpdated Timestamp...\n",timestamp + bdOffset)
返回给定 BusinessDay 对象的增量计数 -
print("\nThe count of increments on the BusinessDay object..\n", bdOffset.n)
以下是代码 -
import datetime import pandas as pd # 在 Pandas 中设置时间戳对象 timestamp = pd.Timestamp('2021-10-30 01:55:02.000045') # 显示时间戳 print("Timestamp...\n",timestamp) # 创建工作日抵消 # BusinessDay 是 DateOffset 子类 bdOffset = pd.tseries.offsets.BusinessDay(n = 6) # 显示工作日偏移 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 count of increments on the BusinessDay object..\n", bdOffset.n)输出结果
这将产生以下代码 -
Timestamp... 2021-10-30 01:55:02.000045 BusinessDay Offset... <6 * BusinessDays> Updated Timestamp... 2021-11-08 01:55:02.000045 Frequency on the given BusinessDay Offset... 6B The count of increments on the BusinessDay object.. 6