批量读取DataFrame内容

con = create_engine('mysql+pymysql://user:password@ip:port/database?charset=utf8')
sql = '查询语句'
cursor = con.execute(sql)
res = cursor.fetchone()
dfs = pd.read_sql(sql, con, chunksize=100000)
for df in dfs:
    df['dd'] = df['dm'] + '. ' + df['dsz']
    for i in df.index.values:
        row_data = df.ix[i, ['id', 'dm', 'dsz', 'dd']].to_dict()
        print(row_data)
    print(df)

你可能感兴趣的:(python)