批量插入数据库
作者:互联网
import pandas as pd from sqlalchemy import create_engine path="C:\\Users\\Administrator\\Desktop\指标\\" data=pd.DataFrame() flile=os.listdir(path) list_len=len(flile) for i in range(list_len): data_exce = pd.read_csv(path + flile[i]) data = data.append(data_exce) data.columns=['ID',"unname",'Country','Countrycode', 'Year', 'Is_Leaf', 'Index_Id', 'Tm_Index_Value', 'Mc_Index_Value'] del data['unname'] print(data) engine=create_engine("mysql+pymysql://root:136382@localhost:3306/wutanghua?charset=utf8") data.to_sql( 'equ', con=engine, if_exists='append',index=False)
标签:engine,Index,批量,数据库,len,插入,pd,path,data 来源: https://www.cnblogs.com/wutanghua/p/16523839.html