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

pandas convert string to date (the string time is B.E year)

I have a data frame in which a column contains a date having time represent in B.E year format

   date
28-01-2562
29-01-2562
30-01-2562
31-01-2562

I tried using pd.to_datetime but its give me an error

  pd.to_datetime(df['date'])

This is the error i got

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

  Out of bounds nanosecond timestamp: 2562-01-30 00:00:00

Thanks.

>Solution :

You can convert values to daily periods:

df['date'] = df['date'].apply(pd.Period)
print (df)
         date
0  2562-01-28
1  2562-01-29
2  2562-01-30
3  2562-01-31
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