Home > Software design >  Convert column to datetime, wrong format
Convert column to datetime, wrong format

Time:08-20

It may be easy to solve, but I am not able to convert a column into a date time. I checked and the format seems right but it does not work

For example, 132550.013906 should be 13:25:50.013906

My df: | | Time| | -------- | -------------- | | 0| 132550.000000| | 1| 132550.013906| | 2| 132550.027219| | 3| 132550.039719| | 4| 132550.044623| | 5| 132550.058625| My code :

df['Time']=pd.to_datetime(df['Time'], format = "%H%M%S.%f" ).map(lambda x: x.time())  

print(df["Time"][0]) 132550.0

ValueError: time data '132550' does not match format '%H%M%S.%f' (match)

CodePudding user response:

I think you missed the . in the time. It's 132550 instead of 132550.XY...

You can change the format to %H%M%S if needed

  • Related