0

I have a column in a dataframe with multiple date formats that need to be converted to datetime.

date              amount
September 2018    15
Sep-18            20

The output should look like

date              amount
2018-09-01        15
2018-09-01        20

Using pd.to_datetime(df['Month']) returns the error...

OutOfBoundsDatetime: Out of bounds nanosecond timestamp: 1-09-18 00:00:00

Ben Sharkey
  • 313
  • 3
  • 15
  • why sep 2018 return 2017 ? – BENY Oct 03 '18 at 02:18
  • sorry, that was a typo – Ben Sharkey Oct 03 '18 at 02:19
  • and why sep-18 is not 2018-09-18 since for me this is make more sense . – BENY Oct 03 '18 at 02:20
  • Sep-18 is in the format Mmm-YY, so needs to be converted to a month and year date format – Ben Sharkey Oct 03 '18 at 02:22
  • [Extracting dates that are in different formats using regex and sorting them - pandas](https://stackoverflow.com/questions/46064162/extracting-dates-that-are-in-different-formats-using-regex-and-sorting-them-pa/) This might help. But needs a bit of alteration. – Bharath M Shetty Oct 03 '18 at 02:23
  • One easy solution is to write your own date parsing function for the data you have and use `df['date'].map(yourfunction)`on the dataframe.Check `df['date'].unique()` to see the date formats. – 576i Oct 03 '18 at 05:32

0 Answers0