Traceback (most recent call last): File "D:\PyCharm\learning\1\BPmain.py", line 14, in <module> train_input=pd.read_excel('test.xlsx', nrows=100, usecols="1:35") File "D:\anaconda\envs\mytest\lib\site-packages\pandas\util\_decorators.py", line 299, in wrapper return func(*args, **kwargs) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\io\excel\_base.py", line 344, in read_excel data = io.parse( File "D:\anaconda\envs\mytest\lib\site-packages\pandas\io\excel\_base.py", line 1179, in parse return self._reader.parse( File "D:\anaconda\envs\mytest\lib\site-packages\pandas\io\excel\_base.py", line 502, in parse usecols = maybe_convert_usecols(usecols) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\io\excel\_util.py", line 150, in maybe_convert_usecols return _range2cols(usecols) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\io\excel\_util.py", line 119, in _range2cols cols.extend(range(_excel2num(rngs[0]), _excel2num(rngs[1]) + 1)) File "D:\anaconda\envs\mytest\lib\site-packages\pandas\io\excel\_util.py", line 86, in _excel2num raise ValueError(f"Invalid column name: {x}") ValueError: Invalid column name: 1 进程已结束,退出代码1
时间: 2023-07-17 09:06:37 浏览: 47
这个错误是由于在读取 Excel 文件时指定的列名无效所导致的。根据错误信息,无效的列名是 "1"。在 `read_excel` 函数中,`usecols` 参数应该接受一个字符串或整数列表来指定要读取的列。确保你传递正确的参数给 `usecols` 参数,例如使用整数列表来指定要读取的列。
参考以下示例代码:
```python
train_input = pd.read_excel('test.xlsx', nrows=100, usecols=[1, 2, 3, 4, 5, ..., 35])
```
请将 `[1, 2, 3, 4, 5, ..., 35]` 替换为你需要读取的列的索引列表。确保索引从0开始,并且没有重复的索引。
如果你想要读取所有列,可以省略 `usecols` 参数,或者将其设置为 `None`。
```python
train_input = pd.read_excel('test.xlsx', nrows=100)
```
希望这可以帮助到你解决问题!如果还有其他问题,请随时提问。
相关问题
Traceback (most recent call last): File "D:\PyCharm\learning\1\11.py", line 159, in <module> n.train(train_input,train_output) File "D:\PyCharm\learning\1\11.py", line 135, in train for j in self.num_input: TypeError: 'int' object is not iterable
根据你提供的错误信息,出现了一个类型错误:`TypeError: 'int' object is not iterable`。这个错误通常发生在你尝试对一个整数对象进行迭代操作时。
根据你提供的代码片段,错误发生在`for j in self.num_input:`这行代码上。`self.num_input`是一个整数,而不是一个可迭代的对象(如列表、元组等)。因此,你不能使用`for`循环对其进行迭代操作。
如果你想要迭代某个范围内的整数,你可以使用`range()`函数来生成一个整数序列,然后进行迭代。例如:
```python
for j in range(self.num_input):
# 在这里执行迭代操作
```
请确保将代码中的`for j in self.num_input:`替换为上述示例代码,以解决这个类型错误。如果问题仍然存在,请提供更多相关的代码和上下文信息,以便我能够提供更准确的帮助。
D:\anaconda\envs\mytest\python.exe D:/PyCharm/learning/1/11.py Traceback (most recent call last): File "D:\PyCharm\learning\1\11.py", line 158, in <module> n.train(train_input) File "D:\PyCharm\learning\1\11.py", line 135, in train inputs = j[0:self.num_in - 1] TypeError: 'float' object is not subscriptable
这个错误是因为你试图对一个浮点数对象进行下标操作,但是浮点数对象是不可被下标的。根据你提供的代码,错误发生在第135行,这行代码尝试对一个名为`j`的浮点数对象进行下标操作。可能是在这之前的代码逻辑有问题,导致`j`被赋值为一个浮点数。你可以检查一下第135行之前的代码,看看是否有地方将`j`赋值为了一个浮点数。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)