A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/read-sql-database-table-into-a-pandas-dataframe-using-sqlalchemy/ below:

Read SQL database table into a Pandas DataFrame using SQLAlchemy

Read SQL database table into a Pandas DataFrame using SQLAlchemy

Last Updated : 27 Jun, 2023

To read sql table into a DataFrame using only the table name, without executing any query we use read_sql_table() method in Pandas. This function does not support DBAPI connections.

read_sql_table()

Syntax : pandas.read_sql_table(table_name, con, schema=None, index_col=None, coerce_float=True, parse_dates=None, columns=None, chunksize=None)

Parameters : 

table_name : (str) Name of SQL table in database.

con : SQLAlchemy connectable or str. 

schema :  (str) Name of SQL schema in database to query (if database flavor supports this). Default is None

index_col : List of string or string. Column(s) to set as index(MultiIndex). Default is None.

coerce_float : (bool) Attempts to convert values of non-string, non-numeric objects (like decimal.Decimal) to floating point.  Default is True

parse_dates : (list or dict) 

columns : List of column names to select from SQL table. Default is None

chunksize : (int) If specified, returns an iterator where chunksize is the number of rows to include in each chunk. Default is None. 

Return type : DataFrame

Example 1 : 

python3
# import the modules
import pandas as pd 
from sqlalchemy import create_engine

# SQLAlchemy connectable
cnx = create_engine('sqlite:///contacts.db').connect()

# table named 'contacts' will be returned as a dataframe.
df = pd.read_sql_table('contacts', cnx)
print(df)

Output : Example 2 : 

python3
# import the modules
import pandas as pd 
from sqlalchemy import create_engine

# SQLAlchemy connectable
cnx = create_engine('sqlite:///students.db').connect()

# table named 'students' will be returned as a dataframe.
df = pd.read_sql_table('students', cnx)
print(df)

Output : Example 3 : 

python3
# import the modules
import pandas as pd 
from sqlalchemy import create_engine

# SQLAlchemy connectable
cnx = create_engine('sqlite:///employee.db').connect()

# table named 'employee' will be returned as a dataframe.
df = pd.read_sql_table('employee', cnx)
print(df)

Output :



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4