1

I currently have a pandas DF with date column in the following format:

JUN 05, 2028

Expected Output:

2028-06-05.

Most of the examples I see online do not use the original format I have posted, is there not an existing solution for this?

Rahul Agarwal
  • 4,034
  • 7
  • 27
  • 51
JS noob
  • 429
  • 5
  • 14
  • Possible duplicate of [How to change the datetime format in pandas](https://stackoverflow.com/questions/38067704/how-to-change-the-datetime-format-in-pandas) – Rahul Agarwal Sep 25 '18 at 14:00

1 Answers1

2

Use to_datetime with custom format from python's strftime directives:

df = pd.DataFrame({'dates':['JUN 05, 2028','JUN 06, 2028']})

df['dates'] = pd.to_datetime(df['dates'], format='%b %d, %Y')
print (df)
       dates
0 2028-06-05
1 2028-06-06
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252