How to change the datetime format in pandas

前端 未结 8 1880
萌比男神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:44

    Changing the format but not changing the type:

    df['date'] = pd.to_datetime(df["date"].dt.strftime('%Y-%m'))
    

提交回复
热议问题