简体   繁体   中英

convert pandas dataframe column of dtype object to date type

I have a dataframe df and has a column by name timeframe of dtype object

column_a timeframe
One nov-21
Two jun-90

I would like to convert timeframe column to date type but this conversion fails with error Out of bounds nanosecond timestamp: 1-11-21 00:00:00

df['timeframe'] = pd.to_datetime(df['Date'])

Specify the format:

df['timeframe'] = pd.to_datetime(df['timeframe'], format="%b-%y", 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