I have a column of timedeltas which have the attributes listed here. I want the output in my pandas table to go from:
1 day, 13:54:03.0456
to:
13:54:03
How can I drop the date from this output?
I have a column of timedeltas which have the attributes listed here. I want the output in my pandas table to go from:
1 day, 13:54:03.0456
to:
13:54:03
How can I drop the date from this output?
You could get seconds of the day with dt.seconds
and then pass that to pd.Timedelta
:
from pandas import Series, date_range
from datetime import timedelta
td = Series(date_range('20130101',periods=4)) - Series(date_range('20121201',periods=4))
td[2] += timedelta(minutes=5,seconds=3)In [321]: td
Out[321]:
0 31 days 00:00:00
1 31 days 00:00:00
2 31 days 00:05:03
3 31 days 00:00:00
dtype: timedelta64[ns]In [322]: td.dt.seconds.apply(lambda x: pd.Timedelta(seconds=x))
Out[322]:
0 00:00:00
1 00:00:00
2 00:05:03
3 00:00:00
dtype: timedelta64[ns]