pandas出错.
# coding:utf-8import os
import pandas as pd
import time
t1 = time.time()
l = []
n = 0
for file in os.walk(r'E:\a'):
for table in file:
path = file + '/' + table
data = pd.read_excel(path, header=0, encoding='utf-8', engine='python')
n = n + 1
l.append(data)
print('第' + str(n) + '个表格已提取')
date_result = pd.concat(l)
date_result.to_excel(r'E:\a\result.excel', index=0)
t2 = time.time()
t2 = t2 - t1
t = round(t2, 2)
print('用时' + str(t) + '秒')
print('完成')
出错,
C:\Users\beluc\AppData\Local\Programs\Python\Python38\python.exe E:/_Python_/删除/鹰紫-合并excel-confired.py
Traceback (most recent call last):
File "E:/_Python_/删除/鹰紫-合并excel-confired.py", line 13, in <module>
data = pd.read_excel(path, header=0, encoding='utf-8', engine='python')
File "C:\Users\beluc\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\excel\_base.py", line 304, in read_excel
io = ExcelFile(io, engine=engine)
File "C:\Users\beluc\AppData\Local\Programs\Python\Python38\lib\site-packages\pandas\io\excel\_base.py", line 813, in __init__
raise ValueError(f"Unknown engine: {engine}")
ValueError: Unknown engine: python 附件里为excel表格文件.谢谢 pandas 文档里写的很清楚 engine : str, default None
If io is not a buffer or path, this must be set to identify io.
Acceptable values are None, "xlrd", "openpyxl" or "odf".engine 只能是 xlrd,openpyxl,odf,你传个 Python 啥意思? fineconey 发表于 2020-5-1 20:30
附件里为excel表格文件.谢谢
噗……能看到吗 data = pd.read_excel(path, header=0, encoding='utf-8')
试试吧 求最佳 MIke_python小小 发表于 2020-5-1 20:40
求最佳
然后提示这个错误
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.
MIke_python小小 发表于 2020-5-1 20:40
求最佳
找到原因了,有个sheetname没搞定.
data = pd.read_excel(path, sheet_name=0, header=None, encoding='utf-8') 你把求最佳设成最佳
不知道的人还以为刷分呢 抱歉,抱歉,的确看走眼了, 感谢提供思路.
页:
[1]