I have csv file with format HH:MM:SS.Milisecond
JavaScript
x
4
1
06:37:46.200
2
06:37:46.600
3
06:37:47.300
4
I want convert that to
JavaScript
1
4
1
23866.200
2
23866.600
3
23867.300
4
How to do that in Pandas latest version (1.4)?
I’ve tried some answers from this forum, but they don’t work on csv and latest version of Pandas.
Advertisement
Answer
Assuming this input:
JavaScript
1
5
1
time
2
0 06:37:46.200
3
1 06:37:46.600
4
2 06:37:47.300
5
You can use pandas.Timedelta.total_seconds
:
JavaScript
1
2
1
pd.to_timedelta(df['time']).dt.total_seconds()
2
output:
JavaScript
1
5
1
0 23866.2
2
1 23866.6
3
2 23867.3
4
Name: time, dtype: float64
5