0

I have a dataframe with two columns of datetime64 format. I have successfully been able to find the difference between them and put that new output in its own column. My query is how do I change the output format I am getting. The output in the new column is like this:

Column1 .... Date_Diff
12345         2 days 
             06:51:58 
56789         4 days
             16:30:22

All I need is the amount of days. The way I created the column is as follows:

df['Date_Diff'] = df.AppointmentDay - df.ScheduledDay 

Is there something I can do to only get the amount of difference in whole days and not have the additional time info? Thanks in advance!

Python3, Pandas 1.4.4

  • 1
    See [this question](https://stackoverflow.com/a/75476796/19123103) for other options. It has a bunch of options to convert to days (and if you want, hours, minutes etc). – cottontail Mar 09 '23 at 18:49

1 Answers1

1

Try the dt accessor with the days attribute. Here is an example:

df['DayDif']= (df['AppointmentDay'] - df['ScheduledDay']).dt.days
amjad khatabi
  • 106
  • 1
  • 5