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 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短