pandas读取mysql数据

其实使用python pandas读取mysql数据是相对比较简单的。 使用了pymysql和sqlalchemy

from sqlalchemy import create_engine
import pymysql

db_connection_str = 'mysql+pymysql://mysql_user:[email protected]_host/mysql_db'
db_connection = create_engine(db_connection_str)

df = pd.read_sql('SELECT * FROM table_name', con=db_connection)

db_connection.dispose()

之前爬虫的数据都是用mysql来存储的,这里就记录一下。

参考:Importing data from a MySQL database into a Pandas data frame including column names

阅读量: | 柯西君_BingWong | 2020-05-30