Answers for "mysql to df"

3

mysql to df

import mysql.connector
import pandas as pd

db_connection = mysql.connector.connect(
  host="localhost",
  user="user",
  password="password",
  database="dbname",
  auth_plugin='mysql_native_password'
)

df = pd.read_sql("select * from table_name;", con=db_connection)
print(df)
Posted by: Guest on July-06-2020
0

python mysql query to dataframe

from sqlalchemy import create_engine
import pymysql

db_connection_str = 'mysql+pymysql://mysql_user:mysql_password@mysql_host/mysql_db'
db_connection = create_engine(db_connection_str)

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

# This works with "mysql.connector" as well
Posted by: Guest on March-30-2020

Python Answers by Framework

Browse Popular Code Answers by Language