0

I am trying to work with some time series data that are in cumulative hours, however I am having trouble getting the times to convert to datetime correctly.

csv format    
cumulative_time,temperature  
01:03:10,30,  
02:03:10,31,  
...  
22:03:10,30,  
23:03:10,29,  
24:03:09,29,  
25:03:09,25,    
etc

df['cumulative_time']=pd.to_datetime(df['cumulative_time'],format='%H:%M:%S').dt.time

keeps yielding the error:

time data '24:03:09' does not match format '%H:%M:%S'

Any thoughts on how to convert just times to datetime format, especially if the hours exceed 24 hours?

NYC Coder
  • 7,424
  • 2
  • 11
  • 24
Ben Whit
  • 3
  • 1

1 Answers1

2

You probably want the pd.to_timedelta function instead.

A "datetime" is a point in time, eg. "at 3pm in the afternoon"; it's complaining about "24:03:09" because that's 0:03:09 the next day.

A "timedelta" is an amount of elapsed time.

Jiří Baum
  • 6,697
  • 2
  • 17
  • 17