0

I wanted to convert the following data into minute, but i always land up on error

time = 0:1:19

time1 = df['time']

time2 = time1.hour * 60 + time1.minute + time1.second

I get this error:

 "AttributeError: 'Series' object has no attribute 'hour'"
Nifim
  • 4,758
  • 2
  • 12
  • 31
  • your first command `time = 0:1:19` is not a valid python command, at least python3 – brunoff Feb 01 '21 at 18:01
  • 1
    Does this answer your question? [How to convert a datetime format to minutes - pandas](https://stackoverflow.com/questions/50392796/how-to-convert-a-datetime-format-to-minutes-pandas) – noah Feb 01 '21 at 18:01
  • 2
    Syntax aside, the number of minutes is hours*60 + minutes + seconds/60. – chepner Feb 01 '21 at 18:02
  • Also you could have a look at this: [convert time hh:mm:ss to minutes -python](https://stackoverflow.com/questions/48447123/convert-time-hhmmss-to-minutes-in-python/48447482) – ClaudiaR Feb 01 '21 at 18:03

1 Answers1

0

use pd.to_timedelta to covnert time to timedelta to get seconds.

time1 = pd.Series(['0:1:19', '1:01:19', '0:0:19'])
obj = pd.to_timedelta(time1)
# convert to minutes
obj.dt.seconds / 60.0

    0     1.316667
    1    61.316667
    2     0.316667
    dtype: float64
Ferris
  • 5,325
  • 1
  • 14
  • 23