import pandas as pd
import pymysql # Linux Windows 都可以用, 可以导入,不能导出, 导出还得要 mysqldb
con = pymysql.connect(host='192.168.9.9', user='admin', passwd='admin', db='test', port = 3306) # 连接
cur = con.cursor()
def read_table(cur, sql_order): # sql_order is a string
try:
cur.execute(sql_order) # 多少条记录
data = cur.fetchall( )
frame = pd.DataFrame(list(data))
except: #, e:
frame = pd.DataFrame()
# print e
# continue
return frame
con.commit()
cur.close()
con.close()
Python 读取 MySQL 数据并转为DataFrame
最新推荐文章于 2024-08-19 10:52:43 发布