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:
Output of read_sql_table
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')
This results in the following output:
Output of read_sql_table with indexing
The columns argument lets us choose specific columns when reading data by passing the column names as a list. Any...