Adding one month to datetime64 with timedelta
问题 When I try this: >>> a = numpy.datetime64('1995-12-31') >>> b = a + pandas.Timedelta(1, unit='M') >>> print(b) I expect to see 1996-01-31 but instead I get 1996-01-30 10:29:06. Any idea why? Many thanks. 回答1: A time delta of one month is the length of a year divided by 12. You need to examine your date and add the appropriate quantity of days. Alternately, increment the month number (rolling over to the next year, if needed), and leave the day number unchanged. 回答2: You can replace the day