Python Pandas - 返回应用于给定 DateOffset 对象的规则代码
要返回应用于给定DateOffset对象的规则代码,请使用offset.rule_codePandas中的。首先,导入所需的库-
from pandas.tseries.frequencies import to_offset import pandas as pd
在Pandas中设置时间戳对象-
timestamp = pd.Timestamp('2021-09-26 03:25:02.000045')创建日期偏移量。我们在这里使用“M”频率增加月份-
offset = to_offset("3M")显示更新的时间戳-
print("\nUpdated Timestamp...\n",timestamp + offset)返回应用于给定DateOffset对象的频率的规则代码-
print("\nThe rule code of the DateOffset object..\n", offset.rule_code)示例
以下是代码-
from pandas.tseries.frequencies import to_offset
import pandas as pd
#在Pandas中设置时间戳对象
timestamp = pd.Timestamp('2021-09-26 03:25:02.000045')
#显示时间戳
print("Timestamp...\n",timestamp)
#创建日期偏移
# We are incrementing the months here using the "M" frequency
offset = to_offset("3M")
#显示日期偏移
print("\nDateOffset...\n",offset)
#显示更新的时间戳
print("\nUpdated Timestamp...\n",timestamp + offset)
#返回应用于给定DateOffset对象的频率的规则代码
print("\nThe rule code of the DateOffset object..\n", offset.rule_code)输出结果这将产生以下代码-
Timestamp... 2021-09-26 03:25:02.000045 DateOffset... <3 * MonthEnds> Updated Timestamp... 2021-11-30 03:25:02.000045 The rule code of the DateOffset object.. M
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短