首页 > 编程语言 > 详细

python—pandas读取excel与写入excel

时间:2020-07-05 18:16:51      阅读:94      评论:0      收藏:0      [点我收藏+]
import pandas as pd
import openpyxl
#将excel数据读取,输出格式为dataframe格式
path = r‘/Users/**/PycharmProjects/class/pyclass1/others/file/学生信息表.xlsx‘
#sheet_name可填写1)excel中表单序号从0开始2)表单名
data = pd.read_excel(path,sheet_name=‘基础信息‘)
#data.head()
print(data)
#将dataframe格式数据写入excel表
path=r‘/Users/**/PycharmProjects/class/pyclass1/others/file/学生信息表2.xlsx‘
data.to_excel(path)


#将多个dataframe写入到一个excel同一sheet页
data1=data.copy()
data2=data.copy()
path1=r‘/Users/**/PycharmProjects/class/pyclass1/others/file/学生信息表合并同表单.xlsx‘
write = pd.ExcelWriter(path1)
data1.to_excel(write)
data2.to_excel(write,startcol= 5)
write.save()
#将多个dataframe写入到一个excel不同sheet页
path2=r‘/Users/**/PycharmProjects/class/pyclass1/others/file/学生信息表合并不同表单.xlsx‘
data3=data.copy()
data4=data.copy()
write = pd.ExcelWriter(path2)
data3.to_excel(write,"sheet1")
data4.to_excel(write,"sheet2")
write.save()

python—pandas读取excel与写入excel

原文:https://www.cnblogs.com/wenchengqingfeng/p/13246814.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!