python—简单几行代码实现Excel直接存储到MySQL

需求:将Excel文件导入数据库中存储
注意:凡是Excel表中的符号全部都用英文符号!!!

演示文件:
在这里插入图片描述实现代码:

import pymysql
import pandas as pd
from sqlalchemy import create_engine

file = r'./data.xlsx'
df = pd.read_excel(file)
engine = create_engine("mysql+pymysql://root:root@localhost:3306/python",encoding='utf-8')

df.to_sql('testexcel',con=engine,if_exists='replace',index=False)

运行结果:
在这里插入图片描述
参考:Excel存入数据库

猜你喜欢

转载自blog.csdn.net/weixin_45666249/article/details/114317951
今日推荐