已经安装了openpyxl还报错xlrd.biffh.XLRDError: Excel xlsx file; not supported
时间: 2023-06-30 09:20:16 浏览: 129
如果你已经安装了openpyxl,但是依然报错`xlrd.biffh.XLRDError: Excel xlsx file; not supported`,那么你可以在`pd.read_excel()`函数中指定`engine='openpyxl'`参数,来告诉pandas使用openpyxl来读取Excel文件。以下是修改后的示例代码:
```python
import pandas as pd
# 读取Excel文件
df = pd.read_excel('your_file.xlsx', sheet_name='your_sheet_name', engine='openpyxl')
# 获取第D列数据
d_col = df['D']
# 打印第D列数据
print(d_col)
```
其中,`your_file.xlsx`是你要读取的Excel文件名,`your_sheet_name`是你要读取的表格名。`engine='openpyxl'`表示使用openpyxl来读取Excel文件。`df['D']`表示获取`df`这个`DataFrame`对象中名为`D`的列。最后,你可以使用`print()`函数打印出获取到的第D列数据。
相关问题
pandas读取xlsx 报错xlrd.biffh.XLRDError: Excel xlsx file; not supported
这个报错是由于在使用 Pandas 读取 Excel 文件时,没有安装 `xlrd` 库或者使用的 `xlrd` 版本不支持读取 `.xlsx` 格式的文件。
要解决这个问题,你可以尝试以下几个方法:
1. 确保你已经安装了 `xlrd` 库。可以使用以下命令来安装最新版本的 `xlrd`:
```python
pip install xlrd
```
2. 如果已经安装了 `xlrd`,但仍然出现问题,那可能是因为 `xlrd` 版本太旧不支持 `.xlsx` 格式。你可以尝试升级 `xlrd` 到最新版本:
```python
pip install --upgrade xlrd
```
3. 如果以上方法都不起作用,那可能是因为 Pandas 默认使用了不支持 `.xlsx` 格式的读取引擎。你可以尝试使用 `openpyxl` 作为读取引擎来读取 `.xlsx` 文件。示例如下:
```python
import pandas as pd
# 使用 openpyxl 作为读取引擎
data = pd.read_excel('file.xlsx', engine='openpyxl')
```
通过指定 `engine='openpyxl'` 参数,可以告诉 Pandas 使用 `openpyxl` 库来读取 Excel 文件。
请注意,如果你选择使用 `openpyxl` 作为读取引擎,你需要确保已经安装了 `openpyxl` 库:
```python
pip install openpyxl
```
通过尝试这些方法,应该能够解决你遇到的 `xlrd.biffh.XLRDError` 异常。
使用pandas读取xlsx表格报错xlrd.biffh.XLRDError: Excel xlsx file; not supported
这个错误是因为pandas默认使用的是xlrd库去读取Excel文件,而xlrd只支持读取xls格式的Excel文件,不支持读取xlsx格式的Excel文件。为了解决这个问题,你可以通过安装openpyxl库来让pandas支持读取xlsx格式的Excel文件。安装openpyxl库的方法是在命令行中输入以下命令:
```
pip install openpyxl
```
安装完成后,你可以使用以下的代码来读取xlsx格式的Excel文件:
```python
import pandas as pd
# 读取xlsx格式的Excel文件
df = pd.read_excel('your_file.xlsx', sheet_name='your_sheet_name')
# 获取第D列数据
d_col = df['D']
# 打印第D列数据
print(d_col)
```
其中,`your_file.xlsx`是你要读取的Excel文件名,`your_sheet_name`是你要读取的表格名。`df['D']`表示获取`df`这个`DataFrame`对象中名为`D`的列。最后,你可以使用`print()`函数打印出获取到的第D列数据。
阅读全文
相关推荐









