Created
July 21, 2020 06:12
-
-
Save BexTuychiev/89ddc9915a0a44b0d72ea65ff30a5349 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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