简体   繁体   中英

Convert date to fixed format python

Team, I need help on converting date column in pandas dataframe. Below is how the date exists 24-NOV-20 04.50.15.981213000 PM .

I need it to convert to '%Y-%m-%d' .

Tried:

 pd.to_datetime().dt.strftime('%Y-%m-%d'). 

But got ValueError: ('Unknown string format:', '24-NOV-20 04.50.15.981213000 PM')

Do this:

df['col'] = pd.to_datetime(df['col'], format='%d-%b-%y %I.%M.%S.%f %p')
df['col'] = df['col'].dt.strftime('%Y-%m-%d')

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