pandas写入MySQL

编程入门 行业动态 更新时间:2024-10-25 16:21:44

<a href=https://www.elefans.com/category/jswz/34/1769643.html style=pandas写入MySQL"/>

pandas写入MySQL

安装好pandas、mysql

pip install pandas
pip install pymysql

导入pandas、mysql

import pymysql as mysql
import pandas as pd

建立连接

con=mysql.connect(host='10.10.0.221',user='root',password='root',database='pandas',port=3306,charset='utf8')

创建游标

cur=con.cursor()

读取本地Excel

df=pd.read_excel(r'c:/users/administrator/desktop/2023-10-20缺货汇总.xlsx')

提交

table = 'quehuo'
columns='仓库代码,仓库名称,物料代码,单据数量,库存可用数量,缺货数量'
for row in df.itertuples(index=False):value=(row.仓库代码,row.仓库名称,row.物料代码,row.单据数量,row.库存可用数量,row.缺货数量)sql = "Insert Into {0} ({1}) values {2}".format(table,columns,value)cur.execute(sql)conmit()

数据及表结构

更多推荐

pandas写入MySQL

本文发布于:2023-12-06 23:23:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1669316.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:pandas   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!