Python Pandas - 作为字符串应用于给定 DateOffset 对象的返回频率
要将应用于给定DateOffset对象的频率作为字符串返回,请使用Pandas中的offset.freqstr属性。
首先,导入所需的库-
from pandas.tseries.offsets import DateOffset import pandas as pd
在Pandas中设置时间戳对象-
timestamp = pd.Timestamp('2021-08-30 02:30:55')创建日期偏移量。我们在这里使用“months”参数增加月份-
offset = pd.tseries.offsets.DateOffset(months=3)
显示更新的时间戳-
print("\nUpdated Timestamp...\n",timestamp + offset)作为字符串应用于给定DateOffset对象的频率-
print("\nFrequency on the given DataOffset...\n",offset.freqstr)示例
以下是代码-
from pandas.tseries.offsets import DateOffset
import pandas as pd
#在Pandas中设置时间戳对象
timestamp = pd.Timestamp('2021-08-30 02:30:55')
#显示时间戳
print("Timestamp...\n",timestamp)
#创建日期偏移
# We are incrementing the months here using the "months" parameter
offset = pd.tseries.offsets.DateOffset(months=3)
#显示日期偏移
print("\nDateOffset...\n",offset)
#显示更新的时间戳
print("\nUpdated Timestamp...\n",timestamp + offset)
#作为字符串应用于给定DateOffset对象的频率
print("\nFrequency on the given DataOffset...\n",offset.freqstr)输出结果这将产生以下代码-
Timestamp... 2021-08-30 02:30:55 DateOffset... <DateOffset: months=3> Updated Timestamp... 2021-11-30 02:30:55 Frequency on the given DataOffset... <DateOffset: months=3>
热门推荐
10 新年门口花束祝福语简短
11 盘锦结婚祝福语大全简短
12 父母生日祝福语 简短独特
13 家庭恩爱祝福语简短英文
14 高考俄语祝福语大全简短
15 虎年祝福语 诗句唯美简短
16 生日婚礼祝福语简短精辟
17 虎年喝酒拜年祝福语简短
18 教师闺蜜祝福语简短