1

I have a weird date format in my data. I currently have 01oct2012 and I would like 01-10-2012. Can someone help me change it! Thank you!

Data

I tried using the pd.to_datetime, but I dont think I have the right code.

eshirvana
  • 23,227
  • 3
  • 22
  • 38
  • Have a looking into the `.strptime` method. This will return a `datetime` object based on the user-defined format of the source date string. – S3DEV Nov 28 '22 at 22:04
  • https://stackoverflow.com/questions/38067704/how-to-change-the-datetime-format-in-pandas Try looking at this , this has been answered previously. – Shreyash Sharma Nov 28 '22 at 22:09

1 Answers1

0

As mentioned above this question has many answers. Taking just 1 date as an example: ts = pd.to_datetime('01oct2012') produces the timestamp:
Timestamp('2012-10-01 00:00:00')

To convert to the desired format:

ts.strftime('%d-%m-%Y')  

yields:
'01-10-2012'

itprorh66
  • 3,110
  • 4
  • 9
  • 21