pandas打开数据库
from sqlalchemy import create_engine
engine=create_engine("mysql+pymysql://root:我的密码@localhost:3306/test1")
df.to_sql(name='test_df',con=engine)
pandas获取数据
from sqlalchemy import create_engine
engine=create_engine("mysql+pymysql://root:我的密码@localhost:3306/test1")
import pymssql
conn = pymysql.connect(
host = 'localhost',
user = 'root',
passwd = '123456',
db = 'mydb',
port=3306,
charset = 'utf8'
)
sql = 'select * from [%s] '%(code)
df = pd.read_sql(sql,conn)