I have a dataframe with at least 2 datetime columns
from io import StringIO
import pandas as pd
dfstr = StringIO(u"""
eqpt;starttm;endtm;use_count;desc
AT1;2017-04-01 10:35;2017-04-01 11:05;2;test asdf1
AT2;2017-04-01 11:00;2017-04-01 11:30;5;test asdf2
AT1;2017-04-01 11:00;2017-04-01 11:30;4;test asdf3
AT3;2017-04-01 10:45;2017-04-01 11:45;3;test asdf4
CBL1;2017-04-01 11:10;2017-04-1 11:40;4;test asdf5
""")
df = pd.read_csv(dfstr, sep=";", parse_dates=["starttm", "endtm"])
I would like to compute the duration of the interruptions between consecutive
starttm
and endtm
I can take the simple difference
r=(df['starttm']-df['endtm'].shift(-1))
But then my result look like
0 -1 days +23:30:00
1 -1 days +23:30:00
2 -1 days +23:30:00
3 -1 days +23:00:00
4 -1 days +23:30:00
dtype: timedelta64[ns]
which is correct numerically. However, I would need it to be in a more human readable format as 0 days -30:00:00
How to round to 0 days?