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

yipeiwu_com6年前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设计】。

相关文章

关于Pytorch的MLP模块实现方式

关于Pytorch的MLP模块实现方式

MLP分类效果一般好于线性分类器,即将特征输入MLP中再经过softmax来进行分类。 具体实现为将原先线性分类模块: self.classifier = nn.Linear(con...

tensorflow使用range_input_producer多线程读取数据实例

先放关键代码: i = tf.train.range_input_producer(NUM_EXPOCHES, num_epochs=1, shuffle=False).dequeu...

transform python环境快速配置方法

经常在数据开发中需要搞udf,最近发现transform更加方便易用,但是经常会涉及到集群python版本不一、包不全或者部分机器上没有安装python。 所以咱们需要快速的进行环境配置...

python如何统计序列中元素

本文实例为大家分享了python统计序列中元素的具体代码,供大家参考,具体内容如下 问题1:        随机数列[12,5...

pycharm编写spark程序,导入pyspark包的3中实现方法

一种方法: File --> Default Setting --> 选中Project Interpreter中的一个python版本-->点击右边锯齿形图标(设置)...