0

I know common question but sort of stuck. I believe I've gotten to the correct format specifier for the to_date function.

I have data that looks like

date
19-SEP-22

I'm trying to convert it to a standard DD/MM/YYYY format

df['date'] = pd.to_datetime(df.date, format='%d-%b-%y')
df['date'] = df['date'].dt.strftime('%d/%m/%Y')

I'm getting error on the first line that the time data does not match the specified format although I believe it should be correct. d for 'dd' b for 'MON' and y for 'yy' am I missing something?

JGH_PC
  • 45
  • 6
  • 1
    It's correct indeed. What might be happening is that you have values with different formats on the date column. – arthurq May 15 '23 at 16:24
  • Thanks, time go digging through this source file. The joys of being in data engineering are endless I tell you. – JGH_PC May 15 '23 at 16:31
  • That data works fine with that code. Please make a [mre]. For specifics, see [How to make good reproducible pandas examples](/q/20109391/4518341). – wjandrea May 15 '23 at 16:31
  • BTW, `to_date` should be `to_datetime`, yeah? – wjandrea May 15 '23 at 16:32

0 Answers0