要显示应用于给定 BusinessDay Offset 对象的关键字参数,请使用BusinessDay.kwdsPandas 中的属性。
首先,导入所需的库 -
import datetime import pandas as pd
在 Pandas 中设置时间戳对象 -
timestamp = pd.Timestamp('2021-10-30 01:55:02.000045')
创建工作日偏移量。BusinessDay 是 DateOffset 子类 -
bdOffset = pd.tseries.offsets.BusinessDay(offset = datetime.timedelta(hours = 7, minutes = 7))
显示更新的时间戳 -
print("\nUpdated Timestamp...\n",timestamp + bdOffset)
显示关键字参数 -
print("\nKeyword arguments on the given BusinessDay Offset...\n",bdOffset.kwds)
以下是代码 -
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(offset = datetime.timedelta(hours = 7, minutes = 7)) # 显示工作日偏移 print("\nBusinessDay Offset...\n",bdOffset) # 显示更新的时间戳 print("\nUpdated Timestamp...\n",timestamp + bdOffset) # 以字符串形式返回应用于给定 BusinessDay 对象的频率 print("\nFrequency on the given BusinessDay Offset...\n",bdOffset.freqstr) # 显示关键字参数 print("\nKeyword arguments on the given BusinessDay Offset...\n",bdOffset.kwds)输出结果
这将产生以下代码 -
Timestamp... 2021-10-30 01:55:02.000045 BusinessDay Offset... <BusinessDay: offset=datetime.timedelta(seconds=25620)> Updated Timestamp... 2021-11-01 09:02:02.000045 Frequency on the given BusinessDay Offset... B+7H7Min Keyword arguments on the given BusinessDay Offset... {'offset': datetime.timedelta(seconds=25620)}