sheet1과 sheet2로 많은 엑셀 파일을 추가하려고합니다. 내가 다음 코드를 파일excel 파일을 파이썬 시트와 병합하십시오.
import os
import pandas as pd
files = os.listdir("C:/Python27/files")
files
df = pd.DataFrame()
for f in files:
data = pd.read_excel(f, 'Sheet1', 'Sheet2')
df = df.append(data)
예를 들어 이름을 쓴 : 총 2014년 4월, 총 팔월 2014
다음 오류입니다 :
Traceback (most recent call last):
File "C:/Python27/filemerge2.py", line 10, in <module>
data = pd.read_excel(f, 'Sheet1', 'Sheet2')
File "C:\Python27\lib\site-packages\pandas\io\excel.py", line 170, in read_excel
io = ExcelFile(io, engine=engine)
File "C:\Python27\lib\site-packages\pandas\io\excel.py", line 227, in __init__
self.book = xlrd.open_workbook(io)
File "C:\Python27\lib\site-packages\xlrd\__init__.py", line 395, in open_workbook
with open(filename, "rb") as f:
IOError: [Errno 2] No such file or directory: 'Total Apr 2014.xls'
그것은 좋은 것입니다 경우 사람 이 오류로 나를 도와 줄 수 있습니다.
감사합니다. @csantos. 지금 새로운 오류가 발생했습니다. 'Traceback (가장 최근에 마지막으로 호출) : 파일 "C : /Python27/filemerge2.py", 줄 9, 데이터 = pd.read_excel (폴더 + '/'+ f, 'Sheet1', 'Sheet2') 파일 "C : \ Python27 \ lib \ site-packages \ pandas \ io \ excel.py", 줄 178, read_excel squeeze = squeeze, ** kwds) 파일 "C : \ Python27 \ lib \ site-packages \ pandas \ io \ excel.py ", 434 줄, _parse_excel 데이터 형식 : [머리글] _trim_excel_header (데이터 머리글) TypeError : 목록 인덱스는 str이 아닌 정수 여야합니다. –
venkatsai
[pandas documentation] (http : /pandas.pydata.org/pandas-docs/stable/generated/pandas.read_excel.html),'read_excel'에 대한 세 번째 매개 변수는 정수 또는 정수 목록이어야하지만 'Sheet2 대신에. – csantos