简体   繁体   中英

Convert column to datetime, wrong format

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM