首页 > 解决方案 > 熊猫 DateOffset 函数

问题描述

以下会返回是否正常True

这背后的想法是什么?

import pandas as pd

t = pd.Timestamp('2017-01-01 00:00:00')
t + pd.DateOffset(month=1) == t

标签: pythonpandas

解决方案


months改为用于month添加价值1,而不是替换,谢谢@splash58:

print (t + pd.DateOffset(months=1) == t)
False

详情

print (t + pd.DateOffset(month=1))
2017-01-01 00:00:00

print (t + pd.DateOffset(months=1))
2017-02-01 00:00:00

如果检查pandas.tseries.offsets.DateOffset.html

**kwds

    Temporal parameter that add to or replace the offset value.

    Parameters that add to the offset (like Timedelta):

        years
        months
        weeks
        days
        hours
        minutes
        seconds
        microseconds
        nanoseconds

    Parameters that replace the offset value:

        year
        month
        day
        weekday
        hour
        minute
        second
        microsecond
        nanosecond

推荐阅读