Python Pandas - 检查 BusinessHour Offset 是否已标准化
要检查BusinessHourOffset是否已标准化,请使用BusinessHour.normalizePandas中的属性。
首先,导入所需的库-
import pandas as pd
在Pandas中设置时间戳对象-
timestamp = pd.Timestamp('2021-1-1 01:55:30')创建营业时间偏移。我们使用“normalize”参数标准化了营业时间-
bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end = "18:00", normalize=True)
显示更新的时间戳-
print("\nUpdated Timestamp...\n",timestamp + bhOffset)检查营业时间偏移是否标准化-
print("\nThe BusinessHour Offset is normalized ?\n", bhOffset.normalize)示例
以下是代码-
import pandas as pd
#在Pandas中设置时间戳对象
timestamp = pd.Timestamp('2021-1-1 01:55:30')
#显示时间戳
print("Timestamp...\n",timestamp)
#创建营业时间偏移
#BusinessHour是DateOffset子类
# Here, "start" is the start time of your custom business hour in 24h format.
# The "end" is the end time of your custom business hour in 24h format.
# We have normalized the BusinessHour using the "normalize" parameter
bhOffset = pd.tseries.offsets.BusinessHour(start="09:30", end = "18:00", normalize=True)
#显示营业时间偏移
print("\nBusinessHour Offset...\n",bhOffset)
#显示更新的时间戳
print("\nUpdated Timestamp...\n",timestamp + bhOffset)
#检查营业时间偏移是否正常化
print("\nThe BusinessHour Offset is normalized ?\n", bhOffset.normalize)输出结果这将产生以下代码-
Timestamp... 2021-01-01 01:55:30 BusinessHour Offset... <BusinessHour: BH=09:30-18:00> Updated Timestamp... 2021-01-01 00:00:00 The BusinessHour Offset is normalized ? True
热门推荐
10 青春告白祖国简短祝福语
11 生日牌祝福语英语简短
12 医政科祝福语简短
13 公司上班祝福语大全简短
14 订婚祝福语简短好听女
15 给表弟的祝福语简短
16 送给老师中秋祝福语简短
17 祝福语诗意文案简短
18 新娘上头祝福语大全简短