Skip to content Skip to sidebar Skip to footer

How Convert An Int64 To Minutes ? Python Pandas

I would like to transform this column (format int64) to a minutes format to do calculation Duration(min) 10 30 5 15 5 I tried this: df['Duration(min)'] = pd.to_datetime(df['Durati

Solution 1:

You need to use pd.to_timedelta here.

pd.to_timedelta(df['Duration(min)'], unit='min')

0   0 days 00:10:00
1   0 days 00:30:00
2   0 days 00:05:00
3   0 days 00:15:00
4   0 days 00:05:00
Name: Duration(min), dtype: timedelta64[ns]

unit -> ‘m’ / ‘minute’ / ‘min’ / ‘minutes’ / ‘T’ all are shorthand for minutes.

Solution 2:

Using pd.to_datetime with strftime -

pd.to_datetime(df.Duration(min), unit='m').dt.strftime('%H:%M')

Output-

000:10100:30200:05300:15400:05dtype:object

Solution 3:

Why %H%M when all you have is minutes? Try format='%M'.

Post a Comment for "How Convert An Int64 To Minutes ? Python Pandas"