0

I have csv file with the date and jobs runtime values, I need to convert the object to time format. Time value will be as follows:

00:04:23
00:04:25

pd.to_datetime(df[‘Time’], format=‘%H:%M:%S:’)

This returns the value with default date

1900-01-01 00:04:23
1900-01-01 00:04:25

How do I retain only the runtime as time data type in the column without date.

Anurag Dabas
  • 23,002
  • 8
  • 19
  • 34

2 Answers2

1

We can make use of to_timedelta function in pandas.

df['Time'] = pd.to_timedelta(df['Time'])

It will create time format of `timedelta64[ns]

maney
  • 74
  • 5
0

You can use pandas.Series.dt.time() to access time part.

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

'''
0    00:04:23
1    00:04:25
Name: Time, dtype: object
'''
Ynjxsjmh
  • 16,448
  • 3
  • 17
  • 42