微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

找出大熊猫偏移量是否为固定偏移量

如何解决找出大熊猫偏移量是否为固定偏移量

有没有办法弄清楚熊猫的偏移量是否固定?目前,我正在尝试通过获取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 举报,一经查实,本站将立刻删除。