问题描述
有没有办法弄清楚熊猫的偏移量是否固定?目前,我正在尝试通过获取nanos
属性来解决此问题,该属性将为非固定偏移量提高ValueError
import pandas as pd
pd.offsets.MonthBegin().nanos
提高
Traceback (most recent call last):
File "<input>",line 1,in <module>
File "pandas/_libs/tslibs/offsets.pyx",line 684,in pandas._libs.tslibs.offsets.BaSEOffset.nanos.__get__
ValueError: <MonthBegin> is a non-fixed frequency
所以我检查它是否固定的方法如下:
def is_fixed_offset(offset: pd.offsets.BaSEOffset):
try:
# non-fixed offsets don't have the `nanos`
# attribute set
offset.nanos
except ValueError:
return False
return True
但这感觉就像我在依赖实现细节。我找不到类似的内置方法。我忽略了什么吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)