利用pandas合并多个excel的方法示例

yipeiwu_com7年前Python基础

具体方法:

1使用panda read_excel 方法加载excel
2使用concat将DataFrame列表进行拼接
3然后使用pd.ExcelWriter对象和to_excel将合并后的DataFrame保存成excel

方法很简单很使用,下面是代码和excel图片

参考文档pandas.DataFrame.to_excel

import pandas as pd
file1='C:/Users/Administrator/Desktop/00/1.xlsx'
file2='C:/Users/Administrator/Desktop/00/3.xlsx'
file3='C:/Users/Administrator/Desktop/00/21.xlsx'
file=[file1,file2,file3]
li=[]
for i in file:
  li.append(pd.read_excel(i))
writer = pd.ExcelWriter('C:/Users/Administrator/Desktop/00/output.xlsx')
pd.concat(li).to_excel(writer,'Sheet1',index=False)
 
writer.save()


如下图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

python二进制读写及特殊码同步实现详解

python对二进制文件的操作需要使用bytes类,直接写入整数是不行的,如果试图使用f.write(123)向文件中以二进制写入123,结果提示参数不是bytes类型。 impor...

python实现生成Word、docx文件的方法分析

本文实例讲述了python实现生成Word、docx文件的方法。分享给大家供大家参考,具体如下: http://python-docx.readthedocs.io/en/latest/...

对Python 文件夹遍历和文件查找的实例讲解

实例如下所示: # -*- coding: utf-8 -*- #to find where use the table on xxxxx xxxxxx production en...

opencv改变imshow窗口大小,窗口位置的方法

如下所示: cv2.HoughLinesP cv2.namedWindow("enhanced",0); cv2.resizeWindow("enhanced", 640, 4...

python3.5使用tkinter制作记事本

tkinter是Python下面向tk的图形界面接口库,可以方便地进行图形界面设计和交互操作编程。tkinter的优点是简单易用、与Python的结合度好。tkinter在Python...