1

I have a column with a birthdate. Some are N.A, some 01.01.2016 but some contain 01.01.2016 01:01:01 Filtering the N.A. values works fine. But handling the different date formats seems clumsy. Is it possible to have pandas handle these gracefully and e.g. for a birthdate only interpret the date and not fail?

Georg Heiler
  • 16,916
  • 36
  • 162
  • 292

1 Answers1

4

pd.to_datetime() will handle multiple formats

>>> ser = pd.Series(['NaT', '01.01.2016', '01.01.2016 01:01:01'])
>>> pd.to_datetime(ser)
0                   NaT
1   2016-01-01 00:00:00
2   2016-01-01 01:01:01
dtype: datetime64[ns]
Asish M.
  • 2,588
  • 1
  • 16
  • 31