需求:将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存入数据库