October 2019
Beginner to intermediate
674 pages
16h 43m
English
Interacting with a SQL database through pandas requires the sqlalchemy dependency to be installed.
First, let's define the engine from which connection parameters can be obtained:
engine = create_engine('sqlite:///:memory:')
Now, let's read the data_sql table from the SQL database:
with engine.connect() as conn, conn.begin(): print(pd.read_sql_table('data_sql', conn))
This results in the following output:

The read_sql_table() function reads an entire table for the given table name. A specific column can be set as the index when reading:
pd.read_sql_table('data_sql', engine, index_col='index')
Read now
Unlock full access