pandas如何在一个Excel文件中写入多个sheet页

要实现这个功能,需要借助于pandas的ExcelWriter()方法,参考如下:

from impala.util import as_pandas# 把数据库中表字段写入到Excel文件中便于查看
curs.execute("""describe ods.table1""")
media = as_pandas(curs)curs.execute("""describe ods.table2""")
customers = as_pandas(curs)curs.execute("""describe ods.table3""")
orders = as_pandas(curs)with pd.ExcelWriter('./潜客表字段.xlsx') as writer: media.to_excel(writer,encoding='utf-8',sheet_name='table1')customers.to_excel(writer,encoding='utf-8',sheet_name='table2')orders.to_excel(writer,encoding='utf-8',sheet_name='table3')print('done')

1. as_pandas包

其中as_pandas是impala.util中的一个非常好用的包,可以直接将数据库读出的结果转为dataframe。

2. describe table查看表结构
这是impala支持的语法,可以查看表结构。spark sql的语法是desc table,有所不同需要注意。

在这里插入图片描述

关注微信公众号:数据分析师手记

数据分析之家联合JEE RAY品牌为粉丝派发福利

在这里插入图片描述
添加粉丝福利派发官,领取粉丝福利哦


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部