Skip to content

Instantly share code, notes, and snippets.

@BexTuychiev
Created July 21, 2020 06:12
Show Gist options
  • Save BexTuychiev/89ddc9915a0a44b0d72ea65ff30a5349 to your computer and use it in GitHub Desktop.
Save BexTuychiev/89ddc9915a0a44b0d72ea65ff30a5349 to your computer and use it in GitHub Desktop.
import pandas as pd
from sqlalchemy import create_engine
engine = create_engine("sqlite:///sample.db")
# Option one
with engine.connect() as connection:
results = connection.execute("""
SELECT column1, column2, column3
FROM table_name
""")
df = pd.DataFrame(results.fetchall())
df.columns = results.keys()
# Option two, my favorite
df = pd.read_sql_query("""
SELECT column1, column2, column3
FROM table_name
""", engine)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment