Python - convert date string from YYYY-MM-DD to DD-MMM-YYYY using datetime?

前端 未结 2 1292
不思量自难忘°
不思量自难忘° 2021-01-23 11:43

So I have read a number of threads on this, and am still stumped. Any help would be sincerely appreciated.

I have a column in a dataframe that contains strings of dates,

2条回答
  •  有刺的猬
    2021-01-23 12:23

    You probably just need to assign the result back to the column itself:

    df_combined['VisitDate'] = df_combined['VisitDate'].apply(lambda x: datetime.datetime.strptime(x, '%Y-%m-%d').strftime('%d-%b-%Y') if x != "" else "")
    

提交回复
热议问题