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

Time:07-04

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

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

Thanks.

CodePudding user response:

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
  • Related