阅读 353

Python Pandas - 返回应用于 CustomBusinessDay 偏移量的增量计数

要返回应用于 CustomBusinessDay 偏移量的增量计数,请使用CustomBusinessDay.nPandas 中的属性。

首先,导入所需的库 -


import pandas as pd


在 Pandas 中设置时间戳对象 -


timestamp = pd.Timestamp('2021-10-22 03:10:35')


创建 CustomBusinessDay 偏移量 -


cbdOffset = pd.tseries.offsets.CustomBusinessDay(n = 4, weekmask = 'Mon Tue Wed Fri')


将偏移量添加到时间戳并显示更新的时间戳 -


print("\nUpdated Timestamp...\n",timestamp + cbdOffset)


返回给定 CustomBusinessDay 对象的增量计数 -


print("\nThe count of increments on the CustomBusinessDay object..\n", cbdOffset.n)


示例

以下是代码 -


import pandas as pd# Set the timestamp object in Pandastimestamp = pd.Timestamp('2021-10-22 03:10:35')# Display the Timestampprint("Timestamp...\n",timestamp)# Create the CustomBusinessDay Offset# CustomBusinessDay is the DateOffset subclass representing custom business days excluding holidays# Weekmask of valid business dayscbdOffset = pd.tseries.offsets.CustomBusinessDay(n = 4, weekmask = 'Mon Tue Wed Fri')# Display the CustomBusinessDay Offsetprint("\nCustomBusinessDay Offset...\n",cbdOffset)# Add the offset to the Timestamp and display the Updated Timestampprint("\nUpdated Timestamp...\n",timestamp + cbdOffset)# Return frequency applied on the given CustomBusinessDay Offset object as a stringprint("\nFrequency applied on the given CustomBusinessDay Offset object...\n",cbdOffset.freqstr)# return the count of increments on the given CustomBusinessDay objectprint("\nThe count of increments on the CustomBusinessDay object..\n", cbdOffset.n)

输出结果


这将产生以下代码 -


Timestamp... 2021-10-22 03:10:35CustomBusinessDay Offset... <4 * CustomBusinessDays>Updated Timestamp... 2021-10-29 03:10:35Frequency applied on the given CustomBusinessDay Offset object... 4CThe count of increments on the CustomBusinessDay object..


文章分类
后端
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐