-1

I am trying to convert a column type to datetime

Value Format in Column: '2016-04-10 12:17:52'

df['dropoff_time']

output
0      2016-04-10 12:17:52
1      2016-04-13 06:44:12
2      2016-04-13 06:54:43
3      2016-04-13 08:33:50
Name: created_at_new, Length: 328, dtype: object

I am trying the following code:

df['created_at_new'] = pd.to_datetime(df['created_at_new'])

ValueError: day is out of range for month

Desired result is a datetime

('2010-11-12 00:00:00')
yatu
  • 86,083
  • 12
  • 84
  • 139

1 Answers1

0

When I tried with the same example, it worked for me. Anyways in order to rectify the error, you can try the following:

  • Check whether you have the latest version of pandas. If not Update it and
  • Try mentioning the date format

df['created_at_new'] = pd.to_datetime(df['created_at_new'], format='%Y-%m-%d %H:%M:%S')

  • Still, if it doesn't work. You can skip the one with error using the argument errors='coerce'. In the place of the skipped one, 'NaT' value will be added.

For more details, you check out this answer.

Senthil Kumar
  • 63
  • 1
  • 8