栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

利用pandas读写excel(xlsx)文件总结

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

利用pandas读写excel(xlsx)文件总结

需要pandas, numpy, openxyl等库
import pandas as pd
##############读文件示例###################################
excelFile = "C:\Users\win10\Desktop\test.xlsx"
df = pd.read_excel(excelFile,sheet_name= "Sheet1")
nrows = df.shape[0]
ncols = df.columns.size
print(nrows)
print(ncols)
print(df.iloc[0,0]) 

##############写文件示例###################################
# stuID = [50101, 50102, 50103, 50104, 50105]
name = ['张三','李四','王五','孙甲','杨乙']
stuID = np.zeros(5)
Chinese = [96, 99, 93, 89, 90]
maths = [100, 99, 99, 92, 95]
English = [98, 98, 95, 90, 91]
data1 = {'学号': stuID, '姓名': name, '语文': Chinese, '数学': maths, '英语': English}
# data1 = {stuID,  Chinese}
df2 = pd.DataFrame(data1)
df2.to_excel('C:\Users\win10\Desktop\test2.xlsx', sheet_name='Sheet1', index=False,header=True)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/850026.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号