'Convert Hour Minute Second Milisecond to total second.milisecond in latest pandas version

I have csv file with format HH:MM:SS.Milisecond

06:37:46.200
06:37:46.600
06:37:47.300

I want convert that to

23866.200
23866.600
23867.300

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.



Solution 1:[1]

Assuming this input:

           time
0  06:37:46.200
1  06:37:46.600
2  06:37:47.300

You can use pandas.Timedelta.total_seconds:

pd.to_timedelta(df['time']).dt.total_seconds()

output:

0    23866.2
1    23866.6
2    23867.3
Name: time, dtype: float64

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mozway