0

Hi im having an issue with when converting the time into timedelta. I managed to keep the time only but it change to an object type. i would like to ask if you can assist me with keeping the time only in timedelta type. below is an example of my dataframe. | Time | ST |S| | ---------------| ---|-| | 0 days 12:09:46| 33 |R| | 0 days 12:09:51| 45 |H|

i tried the following

  n['Time'] = pd.to_timedelta(n['Time'])
# n['Time'] = pd.to_timedelta(n['Time'], unit='s') # error unit must not be specified if the input contains a str
  n['Time'] = n['Time'].astype(str).str.split('0 days ').str[-1] # works but cant 
  resample the data 
  n= n.set_index('Time')#.resample('6s').mean()


It was working before when i chaned to a new laptop 0 days appeared

Thanks for your time and help

SHEHAB
  • 23
  • 6
  • Concerning formatting to string, unfortunately, there's no "strftime" for timedeltas; you'll need a work-around like [this one](https://stackoverflow.com/a/539360/10197418). – FObersteiner Jan 28 '21 at 13:48

1 Answers1

0

We have to drop the column S contacting strings before resampling then 0 days won't affect resampling nor plotting as it is the same across all rows in the data

n= n.drop(['s'], axis = 1)
n['Time'] = pd.to_timedelta(n['Time']) 
n = n.set_index('Time')#.resample('6s').mean()

This works fine Thanks

SHEHAB
  • 23
  • 6