Python Pandas - 检查 CustomBusinessHour Offset 是否已标准化
pythonserver side programmingprogramming更新于 2026/1/29 5:32:17
要检查 CustomBusinessHour Offset 是否已标准化,请使用 Pandas 中的 CustomBusinessHour.normalize 属性。
首先,导入所需的库 −
import pandas as pd
在 Pandas 中设置时间戳对象 −
timestamp = pd.Timestamp('2021-10-25 08:35:10')
创建 CustomBusinessHour Offset。CustomBusinessHour 是 DateOffset 子类。我们已经使用"normalize"对 CustomBusinessDay 进行了规范化。参数 −
cbhOffset = pd.tseries.offsets.CustomBusinessHour(n = 3, weekmask = 'Mon Tue Wed Fri Sat' ,normalize=True)
将偏移量添加到时间戳并显示更新的时间戳 −
print("\n更新的时间戳...\n",timestamp + cbhOffset)
检查 CustomBusinessHour Offset 是否已标准化 −
print("\nCustomBusinessHour Offset 已标准化?\n", cbhOffset.normalize)
示例
以下是代码 −
import pandas as pd
# 在 Pandas 中设置时间戳对象
timestamp = pd.Timestamp('2021-10-25 08:35:10')
# 显示时间戳
print("Timestamp...\n",timestamp)
# 创建 CustomBusinessHour 偏移量
# CustomBusinessHour 是 DateOffset 子类
# 有效工作日的星期掩码
# 我们已经使用"normalize" 对 CustomBusinessDay 进行了规范化参数
cbhOffset = pd.tseries.offsets.CustomBusinessHour(n = 3, weekmask = 'Mon Tue Wed Fri Sat',normalize=True)
# 显示 CustomBusinessHour 偏移
print("\nCustomBusinessHour Offset...\n",cbhOffset)
# 将偏移量添加到时间戳并显示更新的时间戳
print("\n更新时间戳...\n",timestamp + cbhOffset)
# 以字符串形式返回应用于给定 CustomBusinessHour Offset 对象的频率
print("\n应用于给定 CustomBusinessHour Offset 对象的频率...\n",cbhOffset.freqstr)
# 返回应用于给定 CustomBusinessHour 对象的频率的名称
print("\nCustomBusinessHour 对象上的频率名称..\n", cbhOffset.name)
# 检查 CustomBusinessHour Offset 是否已标准化
print("\nCustomBusinessHour Offset 是否已标准化 ?\n", cbhOffset.normalize)
输出
将产生以下代码 −
时间戳... 2021-10-25 08:35:10 CustomBusinessHour Offset... <3 * CustomBusinessHours: CBH=09:00-17:00> 更新时间戳... 2021-10-25 00:00:00 应用于给定 CustomBusinessHour Offset 对象的频率... 3CBH CustomBusinessHour 对象上的频率名称.. CBH CustomBusinessHour Offset 是否已标准化? True
相关文章
有用资源
python 参考教程 - 该教程包含有关 python 的更多信息:https://www.cainiaomax.com/python/
打印
下一节:Python Pandas - 返回应用于给定 CustomBusinessHour 对象的规则代码 ❯❮ 上一节:Python Pandas - 返回在给定的 CustomBusinessHour 偏移对象上应用的频率名称

