Python + pandas connection MySQL query

pymysql Import 
Import PANDAS AS PD 
from SQLAlchemy Import create_engine 

pd.set_option ( 'display.max_columns', 1000) 
pd.set_option ( 'display.width', 1000) 
pd.set_option ( 'display.max_colwidth', 1000) 
pd.set_option ( 'display.max_rows', 1000) 
# of these two parameters are the default setting False 
pd.set_option ( 'display.unicode.ambiguous_as_wide', True) 
pd.set_option ( 'display.unicode.east_asian_width', True) 

    DEF sina_account ( Self, SQL): 
        # initialize the database connection using pymysql module 
        # MySQL user: the root, password: 147369, port: 3306, database: mydb 
        self.engine create_engine = ( '+ MySQL pymysql: // the root: [email protected]. 0.1: 3306 / MySQL ') 
 
        # read_sql_query of two parameters: sql statement, a database connection
        DF = pd.read_sql_query (SQL, Self.engine)

        return df

  

Guess you like

Origin www.cnblogs.com/mtfan01/p/11481215.html