python将dateframe数据存入mysql

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/SuperBoy_Liang/article/details/76534792

import pymysql.cursors
import pandas as pd

conn= pymysql.connect(host='192.168.0.119',port=3306,user='root',passwd='root',
                             db='anjian',
                             charset='utf8',
                             cursorclass=pymysql.cursors.DictCursor)
df=pd.read_excel("a.xlsx")
#index =false 是不展示dataframe的index列  if_exists ‘append’代表 表存在即追加,‘replace’代表重建
df.iloc[:,:].to_sql('texts',conn,flavor='mysql',if_exists='append',index=False)



猜你喜欢

转载自blog.csdn.net/SuperBoy_Liang/article/details/76534792