问题描述
我无法理解某些不一致的行为,因为使用pandas.infer_freq()
函数会为类似的问题返回不同的频率字符串。
在下面的示例中,我创建了一个较小的日期范围。它始终是CET十月时间更改的日期。如果我调用pandas.infer_freq()
,将返回3个不同的字符串。 WOM-4SUN
,H
和None
。
import calendar
import pandas as pd
for year in range(2009,2021):
weekday = calendar.monthrange(year,10)[0]
day = (weekday+30)%7
date_range = pd.date_range(start=f'{year}-10-{30-day} 00:00',end=f'{year}-10-{30-day} 23:00',freq='H',tz='Europe/Berlin'
)
# print the date and the day of week to make sure it`s the last day in october
print(date_range[0].strftime('%Y-%m-%d'),date_range[0].dayofweek)
# print the infered frequency
print(pd.infer_freq(date_range))
这是输出:
2009-10-25 6
WOM-4SUN
2010-10-24 6
H
2011-10-30 6
None
2012-10-28 6
WOM-4SUN
2013-10-27 6
WOM-4SUN
2014-10-26 6
WOM-4SUN
2015-10-25 6
WOM-4SUN
2016-10-30 6
None
2017-10-29 6
None
2018-10-28 6
WOM-4SUN
2019-10-27 6
WOM-4SUN
2020-10-25 6
WOM-4SUN
pandas.infer_freq()
的文档说,它返回的频率最高。有订单(我可以检查)吗?为什么会有不同的结果?为什么不考虑通过日期范围的对象上已经存在的频率?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)