【发布时间】:2017-05-07 06:57:05
【问题描述】:
我正在学习 Python,并且也是第一次尝试使用 pandas。 我有一个目录,其中包含大约 50 个 Excel 工作簿,我正在尝试将其合并为一个。
import openpyxl
import pandas as pd
import numpy as np
import glob
import os
import sys
#path = "\\\\mtrjesmith\\Service Parts Photography Project\\STERISForms"
files = os.listdir("\\\\mtrjesmith\\Service Parts Photography Project\\STERISForms")
outf = "C:\\Python27\\Scripts\\steris_forms\\compiled.xls", "w+b"
#print(files)
frame = [x.parse(x.sheet_names[0], header=None,index_col=None) for x in files]
frame[1:] = [df[1:] for df in frame[1:]]
combined = pd.concat(frame)
combined.to_excel("C:\\Python27\\Scripts\\steris_forms\\compiled.xls", "w+b", header=False, index=False)
我收到以下错误:
Traceback (most recent call last):
File "C:\Python27\Scripts\steris_forms.py", line 18, in <module>
frame = [x.parse(x.sheet_names[0], header=None,index_col=None) for x in files]
AttributeError: 'str' object has no attribute 'parse'
我能做些什么来解决这个问题?任何其他反馈将不胜感激。
【问题讨论】:
-
问题在于
x.parse:x是一个字符串,没有解析方法。 -
您希望
x.parse做什么? -
尝试 pd.ExcelFile.parse
-
我想知道这一行 -- outf = "C:\\Python27\\Scripts\\steris_forms\\compiled.xls", "w+b"
-
@DineshPundkar 我会检查一下,看看我能不能弄明白。