Python Pandas - 从 DateTimeIndex 中提取频率对象作为字符串
要从DateTimeIndex中以字符串形式提取频率对象,请使用Pandas中的DateTimeIndex.freqstr属性。
首先,导入所需的库-
import pandas as pd
创建一个周期为6且频率为D的DatetimeIndex-
datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Adelaide', freq='D')显示日期时间索引-
print("DateTimeIndex...\n", datetimeindex)将DateTimeIndex频率显示为字符串-
print("DateTimeIndex frequency as string...\n", datetimeindex.freqstr)示例
以下是代码-
import pandas as pd
#DatetimeIndex,周期为6,频率为Dieday
#时区是澳大利亚/阿德莱德
datetimeindex = pd.date_range('2021-10-20 02:30:50', periods=6, tz='Australia/Adelaide', freq='D')
#显示日期时间索引
print("DateTimeIndex...\n", datetimeindex)
#显示日期时间索引 frequency
print("DateTimeIndex frequency...\n", datetimeindex.freq)
#显示日期时间索引 frequency as a string
print("DateTimeIndex frequency as string...\n", datetimeindex.freqstr)输出结果这将产生以下代码-
DateTimeIndex... DatetimeIndex(['2021-10-20 02:30:50+10:30', '2021-10-21 02:30:50+10:30', '2021-10-22 02:30:50+10:30', '2021-10-23 02:30:50+10:30', '2021-10-24 02:30:50+10:30', '2021-10-25 02:30:50+10:30'], dtype='datetime64[ns, Australia/Adelaide]', freq='D') DateTimeIndex frequency... <Day> DateTimeIndex frequency as string... D
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短