Pandas - “time data does not match format ” error when the string does match the format?

前端 未结 2 2045
执念已碎
执念已碎 2021-01-15 21:28

I\'m getting a value error saying my data does not match the format when it does. Not sure if this is a bug or I\'m missing something here. I\'m referring to this documentat

2条回答
  •  迷失自我
    2021-01-15 22:21

    You got a special mark here it is not -

    df.iloc[0,0][2]
    Out[287]: '‑'
    

    Replace it with '-'

    pd.to_datetime(df.iloc[:,0].str.replace('‑','-'),format='%d-%b-%Y')
    Out[288]: 
    0    2018-08-27
    1    2018-05-28
    2    2017-06-19
    3    2018-03-05
    4    2018-01-15
    5    2013-11-11
    6    2015-11-23
    7    2014-06-23
    8    2018-06-18
    9    2018-04-30
    10   2018-05-14
    11   2018-04-16
    12   2018-02-26
    13   2018-03-19
    14   2015-06-29
    Name: 2‑Jul‑2018, dtype: datetime64[ns]
    

提交回复
热议问题