簡體   English   中英

用python合並iqy文件

[英]Merging iqy files with python

目前,我從 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")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM