Data Science Asked on July 21, 2021
I want to plot some data that contains timedeltas. However, the numpy plot()
and errorbar()
return:
TypeError: float() argument must be a string or a number, not 'Timedelta'
The question is how can I efficiently convert the timedeltas to a float or integer number. E.g. when I use minutes as base:
0 days 01:30:00 -> 90
or hours
0 days 01:30:00 -> 1.5
Similar to Series.dt.days
which would return 0 in this case.
One way to do this would be to use Series.dt.seconds
and ´Series.dt.days´ and multiply with a factor for the desired unit:
(Series.dt.seconds/3600) + (Series.dt.days*24) # for values with [hours]
Answered by Sören on July 21, 2021
You can divide by the timedelta you want to use as unit:
totalDays = my_timedelta = pd.TimeDelta('1D')
Answered by pqnet on July 21, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP