ValueError time data 202011 doesnt match format Y-m-d HMS at position 1461 You might want to try - passing format if your strings have a consistent format; - passing format=ISO8601 if your strin
The error message you're seeing is a ValueError raised by the datetime.strptime() function. This error occurs when the input string does not match the specified format.
In your case, the input string "2020/1/1" does not match the format "%Y-%m-%d %H:%M:%S". The format "%Y-%m-%d %H:%M:%S" expects the date and time to be in the format YYYY-MM-DD HH:MM:SS.
To resolve this error, you have a few options:
-
Pass the correct format string: If your input string is in the format
YYYY/MM/DD, you should change the format string to"%Y/%m/%d".datetime.strptime("2020/1/1", "%Y/%m/%d") -
Use the
format='ISO8601'argument: If your input strings are all in the ISO8601 format but not necessarily in the exact same format, you can use theformat='ISO8601'argument:datetime.fromisoformat("2020/1/1") -
Use the
format='mixed'argument: If your input strings have mixed formats, you can use theformat='mixed'argument. The format will be inferred for each element individually. You might also want to use thedayfirstargument alongside this:datetime.strptime("2020/1/1", format='mixed', dayfirst=True)
Choose the option that best suits your data and update your code accordingly to fix the ValueError you're encountering.
原文地址: https://www.cveoy.top/t/topic/i3ek 著作权归作者所有。请勿转载和采集!