简体   繁体   中英

Python Pandas to_datetime row by row

How to convert a DF column row by row to_datetime, so when there is a string that is not capable of beeing turned into datetime format, skip that row?

This line of code turns the whole column into datetime format, but some of the rows are set as "friday" and not dates, so I want to skip these rows and format the rest.

df['Dates'] = df['Dates'].apply(pd.to_datetime)

Any help?

This should fix the error you are receiving.

df['Dates'] = df['Dates'].apply(pd.to_datetime, errors='ignore')

Use errors='coerce' for this

df['Date'] = pd.to_datetime(df['Date'], errors='coerce')

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