#导入模块 import pandas from sqlalchemy import create_engine #链接mysql 数据库 con = create_engine(settings.DB_CONFIG)
#读取excel 表格中数据
data = pandas.read_excel(path, encoding='gb18030')
#处理表格中数据,自定义表头(中文为excel 中列名,英文为读取后为数据设置的列索引)
data.rename(columns={'条码': 'id', '名称': 'name', '库存量': 'count', '进货价': 'sprice', '销售价': 'price'}, inplace=True)
#取出指定列的数据
ret=data[['id','name','price','sprice']]
#将数据写入mysql 数据库
et.to_sql(tablename, con=con, if_exists='replace',index=False)