Pandas中的DataFrame读取Mysql的方法
需安装的包
pymysql
pandas
sqlalchemy
import pymysql
import pandas as pd
from sqlalchemy import create_engine
def GetQueryByDF(self,sql):
list_conn = self.GetDBConnectStr()
connect_info = 'mysql+pymysql://{}:{}@{}:{}/{}?charset=utf8'\
.format("user", "passwd", "hostname", "port","dbname")
engine = create_engine(connect_info)
result = pd.read_sql(sql, engine)
return result