用python读取Excel表格时出现的一些问题

import numpy as np
 import pandas as pd
data = pd.DataFrame([])
path='/Users/yingtian/Desktop/读取的文件.xlsx'
f = pd.ExcelFile(path)

此时报错:

Traceback (most recent call last): File “”, line 1, in

f = pd.ExcelFile(path) File “/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_base.py”,
line 1114, in init
self._reader = self._engines[engine](self._io, storage_options=storage_options) File
“/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_xlrd.py”,
line 24, in init
import_optional_dependency(“xlrd”, extra=err_msg) File “/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/compat/_optional.py”,
line 109, in import_optional_dependency
raise ImportError(msg) from None ImportError: Missing optional dependency ‘xlrd’. Install xlrd >= 1.0.0 for Excel support Use pip or
conda to install xlrd.

解决“ImportError: Missing optional dependency ‘xlrd’. Install xlrd >= 1.0.0 for Excel support Use pip or conda to install xlrd.”的方法:
在终端按装xlrd模块:

pip install xlrd

没有成功。
先执行:

engine=‘openpyxl’

然后再执行:

pip install xlrd

安装成功。

Collecting xlrd Downloading xlrd-2.0.1-py2.py3-none-any.whl (96 kB)
|████████████████████████████████| 96 kB 916 kB/s Installing collected packages: xlrd Successfully installed xlrd-2.0.1

重新在python中执行:

f = pd.ExcelFile(path)

此时报错:

Traceback (most recent call last): File “”, line 1, in

f = pd.ExcelFile(path) File “/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/pandas/io/excel/_base.py”,
line 1085, in init
raise ValueError( ValueError: Your version of xlrd is 2.0.1. In xlrd >= 2.0, only the xls format is supported. Install openpyxl
instead.

在终端中执行:

pip install openpyxl

Collecting openpyxl
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘NewConnectionError(’: Failed to establish a new connection: [Errno 60] Operation timed out’)’: /packages/39/08/595298c9b7ced75e7d23be3e7596459980d63bc35112ca765ceccafbe9a4/openpyxl-3.0.7-py2.py3-none-any.whl
Downloading openpyxl-3.0.7-py2.py3-none-any.whl (243 kB)
|████████████████████████████████| 243 kB 320 kB/s

此时

f = pd.ExcelFile(path)

可正常运行。

你可能感兴趣的:(python,bug,python)