Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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'])

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Specify the format:

df['timeframe'] = pd.to_datetime(df['timeframe'], format="%b-%y", errors="coerce")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading