Python Pandas : pandas.to_datetime() is switching day & month when day is less than 13

前端 未结 3 1812
别那么骄傲
别那么骄傲 2020-12-20 16:39

I wrote a code that reads multiple files, however on some of my files datetime swaps day & month whenever the day is less than 13, and any day that is from day 13 or abo

3条回答
  •  抹茶落季
    2020-12-20 17:17

    You can use the dayfirst parameter in pd.to_datetime.

    pd.to_datetime(df.tmp, dayfirst=True)
    

    Output:

    0   2015-06-11 00:56:55
    1   2015-06-11 04:16:38
    2   2015-06-12 16:13:30
    3   2015-06-12 21:24:03
    4   2015-06-13 02:31:44
    5   2015-06-13 02:37:49
    Name: tmp, dtype: datetime64[ns]
    

提交回复
热议问题