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

1 篇文章 0 订阅
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 “<pyshell#5>”, 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 “<pyshell#8>”, 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(’<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7ff598307430>: 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)

可正常运行。

  • 3
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值