1

I'm getting a confusing result when using Python's timestamps and

my_timestamp

Timestamp('2015-06-01 00:00:00')

my_timestamp + relativedelta(month = +4)

Timestamp('2015-04-01 00:00:00')

Naturally I expected the output to Timestamp('2015-10-01 00:00:00')

What is the correct way to add "months" to dates?


[EDIT]: I've since solved this by using the following (in case anyone in Pandas has the same problem):

print my_timestamp
print my_timestamp + DateOffset(months=4)

2015-06-01 00:00:00
2015-10-01 00:00:00

sapo_cosmico
  • 6,274
  • 12
  • 45
  • 58

1 Answers1

4

The issue is that you are using the wrong keyword argument. You want months instead of month.

Per the documentation, month denotes absolute information (not relative) and simply replaces the given information, as you are noting. Using months denotes relative information, and performs the calculation as you'd expect:

Timestamp('2015-06-01 00:00:00') + relativedelta(months=4)

2015-10-01 00:00:00
root
  • 32,715
  • 6
  • 74
  • 87