#-*- coding:utf-8 -*-
from sqlalchemy import create_engine
class mysql_engine():
user='******'
passwd='******'
host='******'
port = '******'
db_name='******'
engine = create_engine('mysql://{0}:{1}@{2}:{3}/{4}?charset=utf8'.format(user,passwd,host,port,db_name))
def write_data(dataframe):
pg_enine=mysql_engine()
try:
with pg_enine.engine.connect() as con, con.begin():
pd.io.sql.to_sql(dataframe,'tablename', con, schema='dbname', if_exists='append')
con.close()
except Exception,e:
print e
注:pd 1.9以后的版本,除了sqllite,均需要通过sqlalchemy来设置