利用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设计】。

相关文章

Django objects.all()、objects.get()与objects.filter()之间的区别介绍

前言 本文主要介绍的是关于Django objects.all()、objects.get()与objects.filter()直接区别的相关内容,文中介绍的非常详细,需要的朋友们下面来...

python 实现在Excel末尾增加新行

实例如下所: import os import xlrd import xlwt from xlutils.copy import copy def excelwrite(L=No...

python打开使用的方法

python打开使用的方法

python怎么打开使用? 1、首先需要打开电脑的桌面,如图所示,并按开始的快捷键点击安装好的python3.6程序进入。 2、然后点击进入之后,如图所示,可以看到页面上面的三个大于号...

python中pandas.DataFrame排除特定行方法示例

前言 大家在使用Python进行数据分析时,经常要使用到的一个数据结构就是pandas的DataFrame,关于python中pandas.DataFrame的基本操作,大家可以查看这篇...

关于numpy.where()函数 返回值的解释

近日用到numpy.where()函数,大部分使用方式都能理解,但是在看 >>> x = np.arange(9.).reshape(3, 3) >>&...