python—pandas读取excel与写入excel


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()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM