Convert DataFrame column type from string to datetime, dd/mm/yyyy format

后端 未结 4 828
花落未央
花落未央 2020-11-22 10:13

How can I convert a DataFrame column of strings (in dd/mm/yyyy format) to datetimes?

4条回答
  •  粉色の甜心
    2020-11-22 10:45

    You can use the following if you want to specify tricky formats:

    df['date_col'] =  pd.to_datetime(df['date_col'], format='%d/%m/%Y')
    

    More details on format here:

    • Python 2 https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior
    • Python 3 https://docs.python.org/3.7/library/datetime.html#strftime-strptime-behavior

提交回复
热议问题