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 关于老人的祝福语简短