Pandas - Converting date column from dd/mm/yy hh:mm:ss to yyyy-mm-dd hh:mm:ss

后端 未结 2 484
旧巷少年郎
旧巷少年郎 2021-02-08 22:54

I have a dataframe (df) that has a date column (column name : sale_date) that stores data in the below format

dd/mm/yy hh:mm:ss

I am trying to

2条回答
  •  清酒与你
    2021-02-08 23:42

    You can do so:

    df['sale_date'] = pd.to_datetime(df['sale_date'], format='%d/%m/%y %H:%M:%S').dt.strftime('%Y-%m-%d %H:%M:%S')
    

    Input:

               sale_date
    0  04/12/10 21:12:35
    1  04/12/10 21:12:30
    

    Output:

                 sale_date
    0  2010-12-04 21:12:35
    1  2010-12-04 21:12:30
    

提交回复
热议问题