pubilcTreat

python连接数据库到excel 第二回

复制代码
#使用前建议看一下sqllalchemy和create_engine,主要就是数据库拉数据导入excel 
#下面是代码部分
from
sqlalchemy import create_engine ,text #利用sqlalchemy 顺带用create_engine,text 区分大小写 import pandas as pd # host='cs-' user='root' password='6Ep' db='performa' port=4055 engine=create_engine('mysql+pymysql://%s:%s@%s:%s/%s?charset=utf8'%(user,password,host,port,db)) data=pd.read_sql(text('select * from cond_instances'),engine.connect()) print(data) data.to_excel('敬山2.xlsx',index=False)
复制代码

接下来就是进阶部分得要看python书籍和要学习的方向了。为了自己多努力还是得要多写写博客。这样自己始终没有退步

 

posted on   pubilcTreat  阅读(27)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示