Skip to content

Instantly share code, notes, and snippets.

@rahman9909
Forked from stefanthoss/mysql-pandas-import.py
Created September 15, 2018 22:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahman9909/6b8284e07cf3c61537e6ca815d5da658 to your computer and use it in GitHub Desktop.
Save rahman9909/6b8284e07cf3c61537e6ca815d5da658 to your computer and use it in GitHub Desktop.
Import data from a MySQL database table into a Pandas DataFrame using the pymysql package.
import pandas as pd
import pymysql
from sqlalchemy import create_engine
engine = create_engine('mysql+pymysql://<user>:<password>@<host>[:<port>]/<dbname>')
df = pd.read_sql_query('SELECT * FROM table', engine)
df.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment