1 Star 0 Fork 14

Joe/ant-learn-python-100P

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
p054_insert_mysql_excel.py 569 Bytes
一键复制 编辑 原始数据 按行查看 历史
peiss 提交于 2021-08-09 22:07 . 'xx'
import pandas as pd
import pymysql
conn = pymysql.connect(
host='127.0.0.1',
user='root',
passwd='12345678',
port=3306,
db='db_school',
charset='utf8'
)
df = pd.read_excel("2020按季度学生成绩表.xlsx")
for idx, row in df.iterrows():
print(f"process: {row.sno}, {row.course}")
sql = f"""
insert into student_grade
(quarter, sno, course, grade)
values ('{row.quarter}', '{row.sno}', '{row.course}', '{row.grade}')
"""
cursor = conn.cursor()
cursor.execute(sql)
conn.commit()
conn.close()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/stayhungry2022/ant-learn-python-100P.git
[email protected]:stayhungry2022/ant-learn-python-100P.git
stayhungry2022
ant-learn-python-100P
ant-learn-python-100P
master

搜索帮助