Python Pandas - 返回给定 BusinessDay 偏移对象上应用的频率名称
要返回给定 BusinessDay 偏移对象上应用的频率名称,请在 Pandas 中使用 BusinessDay.name 属性。
首先,导入所需的库 -
import datetime import pandas as pd
在 Pandas 中设置时间戳对象 -
timestamp = pd.Timestamp('2021-10-30 01:55:02.000045')
创建 BusinessDay 偏移量。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
# Set the timestamp object in Pandas
timestamp = pd.Timestamp('2021-10-30 01:55:02.000045')
# Display the Timestamp
print("Timestamp...\n",timestamp)
# Create the BusinessDay Offset
# BusinessDay is the DateOffset subclass
bdOffset = pd.tseries.offsets.BusinessDay(offset = datetime.timedelta(hours = 8, minutes = 10))
# Display the BusinessDay Offset
print("\nBusinessDay Offset...\n",bdOffset)
# Display the Updated Timestamp
print("\nUpdated Timestamp...\n",timestamp + bdOffset)
# return the frequency applied on the given BusinessDay object as a string
print("\nFrequency on the given BusinessDay Offset...\n",bdOffset.freqstr)
# return the name of the frequency applied on the given BusinessDay object
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
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP