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