Home > Net >  Calculate orders time
Calculate orders time

Time:11-23

I have a dataframe with purchase orders, some orders have already expired and they have the time_end field filled in. Other order may be repeated and have the same billing time. Is it possible to somehow calculate how long exactly the applications stood in the interval 10:00:00 - 18:28:00. That is, to find as a percentage how long the applications stood: time, how long the applications stood / for the time interval (18:28:00 - 10:00:00 = 8:28:00)

        time                  time_end
0   2021-11-22 07:00:34.721000  NaT
1   2021-11-22 07:01:51.444000  NaT
2   2021-11-22 07:03:22.050001  NaT
3   2021-11-22 07:01:51.444000  2021-11-22 07:03:59.291
4   2021-11-22 07:05:26.712001  NaT
5   2021-11-22 07:00:34.721000  2021-11-22 07:05:43.755
6   2021-11-22 07:05:54.851000  NaT
7   2021-11-22 07:08:24.409000  NaT

CodePudding user response:

Compute the total interval in seconds:

interval = (pd.to_datetime('14:40') - pd.to_datetime('13:40')).seconds

Find the difference between the two time columns in seconds and divide:

(df['time_end'] - df['time']).dt.total_seconds() / interval
  • Related