Traceback (most recent call last) <ipython-input-76-72c1700c5bf2> in <module> 10 wb.close() 11 for i in date: ---> 12 d = datetime.strptime(i, "%Y-%m-%d") 13 s.append(d) 14 date=set(s) D:\ProgramData\Anaconda3\lib\_strptime.py in _strptime_datetime(cls, data_string, format) 575 """Return a class cls instance based on the input string and the 576 format string.""" --> 577 tt, fraction, gmtoff_fraction = _strptime(data_string, format) 578 tzname, gmtoff = tt[-2:] 579 args = tt[:6] + (fraction,) D:\ProgramData\Anaconda3\lib\_strptime.py in _strptime(data_string, format) 360 if len(data_string) != found.end(): 361 raise ValueError("unconverted data remains: %s" % --> 362 data_string[found.end():]) 363 364 iso_year = year = None ValueError: unconverted data remains:
时间: 2024-02-14 17:28:26 浏览: 151
这个错误是由于在使用`datetime.strptime()`函数时,解析日期字符串时出现了格式不匹配的问题。根据您提供的代码和错误信息,看起来日期字符串中包含了额外的空格字符。这个问题可以通过使用`str.strip()`函数来去除字符串两端的空格解决。
请将第12行代码修改为以下形式:
```python
d = datetime.strptime(i.strip(), "%Y-%m-%d")
```
这样就可以解决这个错误了。如果您还有其他问题,请随时提问。
相关问题
AttributeError Traceback (most recent call last) <ipython-input-26-7401c2f31978> in <module>
It seems like you are trying to run some code in Python and getting an `AttributeError`. Can you please provide more information about the error, such as the full traceback and the code that you are running?
ModuleNotFoundError Traceback (most recent call last) <ipython-input-4-7d102e6f41ec> in <module>
ModuleNotFoundError是Python中的一个异常类型,表示在导入模块时找不到指定的模块。当Python解释器在执行代码时遇到import语句,它会尝试在指定的路径中查找并加载相应的模块文件。如果找不到对应的模块文件,就会抛出ModuleNotFoundError异常。
常见导致ModuleNotFoundError异常的原因包括:
1. 模块未安装:如果你尝试导入一个未安装的模块,就会出现该异常。你需要使用pip或conda等包管理工具安装相应的模块。
2. 模块路径错误:Python解释器会按照一定的规则搜索模块文件,如果模块文件不在搜索路径中,就会出现该异常。你可以通过添加模块所在路径到sys.path或设置PYTHONPATH环境变量来解决该问题。
3. 模块名称错误:如果你输入的模块名称有误,就会导致找不到模块。请确保输入的模块名称正确无误。
阅读全文
相关推荐
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)