python如何实现工作表合并?
python如何实现工作表合并?
传统方法上,想要对工作表进行合并,通常就是采用复制黏贴,不过,缺点就是工作表的格式会发生改变,并且还是比较浪费时间的事情,因此,能够自动化的去实现合并工作表,还是相当重要的,所以在python中有很多库,能够帮助我们去解决职场上所遇到的各种问题,真正意义上实现自动化,下面来看下实现工作表合并的方法吧。
合并步骤:
1、获取所有的sheet表
2、转化列表推导式
3、调用pandas库
4、使用concat()方法
5、进行sheet表连接
实现代码:
importpandasaspd
importos
curpath=os.path.dirname(__file__)
filename=os.path.join(curpath,'example_split.xlsx')
savefilename=os.path.join(curpath,'example_split_1.xlsx')
df=pd.read_excel(filename,sheet_name=None)
print(type(df))
dfs=[yforx,yindf.items()]
writer=pd.ExcelWriter(savefilename,engine='openpyxl',mode='a')
df2=pd.concat(dfs)
print(df2)
df2.to_excel(writer,'汇总表',index=False)
writer.save()
使用python在我们工作上实现自动化处理是相当方便的,大家要是遇到需要合并表的话,可以利用这种方式哦~更多Python学习教程请关注IT培训机构:千锋教育。

相关推荐HOT
更多>>
python函数标注是什么
python函数标注是什么在参数的使用方法中,还有一种解包的情况是需要我们掌握的。比如,将列表或者字典的值转换为函数的参数,就需要用到参数解...详情>>
2023-11-14 14:13:35
python正负索引的使用
python正负索引的使用本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、说明使用正索引(从左至右)、负索引(从右至左)访问元素,时...详情>>
2023-11-14 13:45:04
python垃圾回收的机制过程
python垃圾回收的机制过程本文教程操作环境:windows7系统、Python3.9.1,DELLG3电脑。1、步骤(1)收集所有容器对象(list,dict,tuple,customClas...详情>>
2023-11-14 13:05:15
pythontry语句的执行原理
pythontry语句的执行原理1、原理分析(1)执行try子句(try和except关键字之间的多行语句)。(2)如果没有异常发生,则跳过except子句并完成try语句...详情>>
2023-11-14 09:37:35热门推荐
技术干货






