Home > Enterprise >  How to calculate time difference in minutes from 2 data frame columns in Pandas
How to calculate time difference in minutes from 2 data frame columns in Pandas

Time:11-10

I have 2 Panda data frame columns in datetime format and want to get time difference in minutes. with my code I get output (out put dtype is "timedelta64[ns]") with days and hours etc. How can I get it in minutes. Thank you

df['TIME_TO_REPORT']= df['TEST_TIME'] - df['RECEIPT_DATE_TIME']

Out put

    0        0 days 05:58:00
    1        0 days 03:46:00
    2        0 days 05:25:00
    3        0 days 05:24:00
    4        0 days 05:24:00

CodePudding user response:

Use total_seconds to get the time duration in seconds, and then divide by 60 to convert it to minutes

df['TIME_TO_REPORT']= (df['TEST_TIME'] - df['RECEIPT_DATE_TIME']).dt.total_seconds() / 60
  • Related