Traceback (most recent call last): File "E:\pythonProject\task4\demo1.py", line 6, in <module> data.支付时间=pd.to_datetime(data.支付时间,format='%Y/%m/%d') File "E:\Python\lib\site-packages\pandas\core\tools\datetimes.py", line 1050, in to_datetime values = convert_listlike(arg._values, format) File "E:\Python\lib\site-packages\pandas\core\tools\datetimes.py", line 453, in _convert_listlike_datetimes return _array_strptime_with_fallback(arg, name, utc, format, exact, errors) File "E:\Python\lib\site-packages\pandas\core\tools\datetimes.py", line 484, in _array_strptime_with_fallback result, timezones = array_strptime(arg, fmt, exact=exact, errors=errors, utc=utc) File "pandas\_libs\tslibs\strptime.pyx", line 530, in pandas._libs.tslibs.strptime.array_strptime File "pandas\_libs\tslibs\strptime.pyx", line 355, in pandas._libs.tslibs.strptime.array_strptime ValueError: unconverted data remains when parsing with format "%Y/%m/%d": " 0:53", at position 0. You might want to try: - passing `format` if your strings have a consistent format; - passing `format='ISO8601'` if your strings are all ISO8601 but not necessarily in exactly the same format; - passing `format='mixed'`, and the format will be inferred for each element individually. You might want to use `dayfirst` alongside this.
时间: 2023-08-27 17:05:29 浏览: 275
浅谈Python traceback的优雅处理
这个错误提示显示在使用 `pd.to_datetime()` 函数时,出现了解析格式(`'%Y/%m/%d'`)与数据不匹配的问题。错误信息中还提示了一些解决方案,你可以尝试一下:
- 如果你的字符串具有一致的格式,可以尝试传递 `format` 参数以匹配你的数据格式。
- 如果你的字符串都是 ISO8601 格式,但格式可能不完全相同,可以尝试传递 `format='ISO8601'` 参数。
- 如果你的字符串格式混杂不一,可以传递 `format='mixed'` 参数,pandas会为每个元素分别推断日期格式。同时你可能还需要使用 `dayfirst` 参数,以处理日期在月份之前的情况。
你可以根据自己的数据情况选择合适的解决方法。
阅读全文