How to change the datetime format in pandas

前端 未结 8 1892
萌比男神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 is the code worked for me, And we need to be very careful for format. Below link will be definitely useful for knowing your exiting format and changing into desired format(Follow strftime() and strptime() Format Codes on below link):

    https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior.

    data['date_new_format'] = pd.to_datetime(data['date_to_be_changed'] , format='%b-%y')
    

提交回复
热议问题