Python Pandas - 返回应用于给定 BusinessDay 偏移对象的频率名称
要返回应用于给定BusinessDay偏移量对象的频率名称,请使用BusinessDay.namePandas中的属性。
首先,导入所需的库-
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 = 8, minutes = 10))
显示更新的时间戳-
print("\nUpdated Timestamp...\n",timestamp + bdOffset)
返回应用于给定BusinessDay对象的频率名称-
print("\nThe name of the frequency on the BusinessDay object..\n", bdOffset.name)
示例
以下是代码-
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 = 8, minutes = 10)) #显示工作日偏移 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)输出结果
这将产生以下代码-
Timestamp... 2021-10-30 01:55:02.000045 BusinessDay Offset... <BusinessDay: offset=datetime.timedelta(seconds=29400)> Updated Timestamp... 2021-11-01 10:05:02.000045 Frequency on the given BusinessDay Offset... B+8H10Min The name of the frequency on the BusinessDay object.. B