Querying relational databases directly with pandas

Introduction to Importing Data in Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

The pandas way to query

from sqlalchemy import create_engine
import pandas as pd
engine = create_engine('sqlite:///Northwind.sqlite')
with engine.connect() as con:
    rs = con.execute("SELECT * FROM Orders")
    df = pd.DataFrame(rs.fetchall())
    df.columns = rs.keys()
df = pd.read_sql_query("SELECT * FROM Orders", engine)
Introduction to Importing Data in Python

Let's practice!

Introduction to Importing Data in Python

Preparing Video For Download...