0

below are my codes

df = pd.DataFrame({'Date' : ['2014-03-27', '2014-03-28', '2014-03-31', '2014-04-01', '2014-04-02', '2014-04-03', '2014-04-04', '2014-04-07','2014-04-08', '2014-04-09'],
})

df['Date'] = pd.to_datetime(df['Date'])

df['days'] = df['Date'].shift(-1) - df['Date']

The output I get is something like this

enter image description here

But I want the output in the form of integer not timedelta. is there an easy way to convert in the codes?

user13412850
  • 509
  • 1
  • 5
  • 16
  • 2
    I feel like this answer is quite on point (and also, very well solved imho) https://stackoverflow.com/questions/37840812/pandas-subtracting-two-date-columns-and-the-result-being-an-integer/46966942 – Carlo Aug 04 '21 at 09:31
  • absolutely totally agreed, it just hit the nail! thanks again @Carlo – user13412850 Aug 04 '21 at 09:34

0 Answers0