熊猫DateOffset函数

时间:2019-11-12 09:45:53

标签: python pandas

以下内容返回True是否正常?

其背后的想法是什么?

import pandas as pd

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

1 个答案:

答案 0 :(得分:1)

使用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