Python 不支持操作:从zip文件读取excel文件时搜索

Python 不支持操作:从zip文件读取excel文件时搜索,python,pandas,Python,Pandas,我只想从一个zip文件中读取不同的excel文件。请建议错误的解决方案或其他方法 df=pd.DataFrame() for zip_file in glob.glob("/content/drive/My Drive/file.zip"): zf = zipfile.ZipFile(zip_file) for f in zf.namelist(): print(f) #f=f.replace('XLSX','xlsx')

我只想从一个zip文件中读取不同的excel文件。请建议错误的解决方案或其他方法

df=pd.DataFrame()
for zip_file in glob.glob("/content/drive/My Drive/file.zip"):
    zf = zipfile.ZipFile(zip_file)
    for f in zf.namelist():
      print(f)
      #f=f.replace('XLSX','xlsx')
      print(zf.open(f))
      dfs=pd.read_excel(zf.open(f)) 
      df = pd.concat([df,dfs],ignore_index=True)
以下代码给出了错误信息:
取消支持操作:查找

如果您只读取一个.zip文件,则不需要
glob.glob

编辑: 刚刚试过你的代码,它也能工作。作为补充说明,最好只对pandas.DataFrames列表使用一次
pd.concat()
,因为当前它每次都创建新的pandas数据帧,并反复分配内存

导入zipfile
作为pd进口熊猫
dfs=[]
zf=zipfile.zipfile(“files.zip”)
对于zf.namelist()中的f:
如果不是f.lower().endswith(“.xlsx”):
持续
dfs.append(pd.read_excel(zf.open(f)))
df=pd.concat(dfs,忽略索引=True)