使用pandas获取MySQL数据库中的数据

import pymysql
import pandas as pd
from sqlalchemy import create_engine

初始化数据库连接,使用pymysql模块

MySQL的用户:root, 密码:你的密码, 端口:3306,数据库:trust

engine = create_engine("mysql+pymysql://root:password@localhost:3306/trust",encoding='utf-8')

查询语句,选出testexcel表中的所有数据

sql = "select * from testexcel"

read_sql_query的两个参数: sql语句, 数据库连接

df = pd.read_sql_query(sql,con=engine)
发布了49 篇原创文章 · 获赞 13 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_44166997/article/details/97370064