pandas+sqlalchemy 保存数据到mysql

import pandas as pd
from sqlalchemy import create_engine

data3={"lsit1":[1,2],"lsit2":[3,4],"lsit3":[5,6]}   # use tuple tuple or dictionary list


df=pd.DataFrame(data3)

df.to_csv('weiboi.csv', encoding='gb2312', index = False) #insert into csv
df.to_excel('weiboi.xlsx', encoding='gb2312', index=False,sheet_name="sheet2")#insert into excel
yconnect = create_engine('mysql+pymysql://root:Aa1234@127.0.0.1:3306/ptos?charset=utf8')
pd.io.sql.to_sql(datatosql, 'tablename', yconnect, schema='ptos', if_exists='append')  #insert into sql 

  

posted @ 2018-02-22 16:35  公众号python学习开发  阅读(435)  评论(0编辑  收藏  举报