How to change the datetime format in pandas

前端 未结 8 1914
萌比男神i
萌比男神i 2020-11-21 23:26

My dataframe has a DOB column (example format 1/1/2016) which by default gets converted to pandas dtype \'object\': DOB object

8条回答
  •  孤街浪徒
    2020-11-21 23:49

    Below code changes to 'datetime' type and also formats in the given format string. Works well!

    df['DOB']=pd.to_datetime(df['DOB'].dt.strftime('%m/%d/%Y'))
    

提交回复
热议问题