python - 用python合并iqy文件

标签 python excel pandas merging-data

目前我从 sharepoint 中提取数据并拥有可以用 excel 打开的 .iqy 文件。大约有 30 个文件,我正在尝试使用 python 将所有信息合并到一个 .iqy 文件或 excel 文件中。

import os, glob
import pandas as pd

files = []
for file in os.listdir("C:\\Users\\CHI86786\\Downloads"):
    files.append(file)

excels = [pd.ExcelFile(name) for name in files]
frames = [x.parse(x.sheet_names[0], header=None, index_col=None) for x in excels]

frames[1:] = [df[1:] for df in frames[1:]]

combined = pd.concat(frames)
combined.to_excel("SPmerged.iqy", header=False, index=False)

采用与合并 excel 文件相同的方法。但我不断收到错误消息 FileNotFoundError: [Errno 2] No such file or directory: 'desktop.ini'

编辑

更多错误信息

File "C:\Users\CHI\source\repos\MergingExcel\MergingExcel\MergingExcel.py", line 8, in <module>
    excels = [pd.ExcelFile(name) for name in files] #reads names in
  File "C:\Users\CHI86786\source\repos\MergingExcel\MergingExcel\MergingExcel.py", line 8, in <listcomp>
    excels = [pd.ExcelFile(name) for name in files] #reads names in
  File "C:\Users\CHI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\io\excel.py", line 394, in __init__
    self.book = xlrd.open_workbook(self._io)
  File "C:\Users\CHI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlrd\__init__.py", line 116, in open_workbook
    with open(filename, "rb") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'desktop.ini'

最佳答案

您的代码试图对 C:\Users\CHI86786\Downloads 中的每个文件执行操作,包括系统文件,如“desktop.ini”。

相反,请尝试将其限制为您感兴趣的文件,使用 glob :

for file in glob.glob("C:\\Users\\CHI86786\\Downloads\\*.iqy")

关于python - 用python合并iqy文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51864417/

相关文章:

c# - Excel.Chart.Export 不工作

linux - 在 Linux 服务器上将 Excel 提取为文本

python - dataframe.to_hdf() 中的参数键是什么意思

python - 在具有多个相同数据的数据框中取最佳值

python - 在 Python 列表中查找子字符串

vba - Excel:如何比较来自 2 个不同工作簿的工作表的差异

python - 在一个端点 django rest 框架中使用两个不同的序列化程序

python - 如何在某一位置将列从一个数据帧插入/移植到另一个数据帧?

python - 聚类余弦相似度矩阵

python - 如何将 scrapy 图像下载到动态文件夹中?