Name of the Database table to collect data to DataFrame
con
Database connection string
schema
default = None, Name of the Schema in Database
index_col
Column to be used as index in DataFrame
coerce_float
bool, Converts non-string, non-numeric to float
parse_date
default=None, List of columns to be parse as Date
columns
List of columns to return, by default all columns are available
chunksize
Number of rows to be included on each Chunk, iterator is returned.
Database Connection
We will use SQLAlchemy to connect to MySQL database.
We used our sample table student.
Query and display record
Replace your MySQL login details.
import pandas as pd
from sqlalchemy import create_engine
my_conn = create_engine("mysql+mysqldb://root:test@localhost/my_tutorial")
my_data = pd.read_sql_table('student',my_conn)
print(my_data)
Output-There are 35 records , sample records are shown here.
id name class mark gender
0 1 John Deo Four 75 female
1 2 Max Ruin Three 85 male
2 3 Arnold Three 55 male
3 4 Krish Star Four 60 female
4 5 John Mike Four 60 female
-------
-------
index_col
You can see there is one index column in our table id. We can use that as our index. The sql and display part only changes here.
name class mark gender
id
1 John Deo Four 75 female
2 Max Ruin Three 85 male
3 Arnold Three 55 male
name class mark gender
id
4 Krish Star Four 60 female
5 John Mike Four 60 female
6 Alex John Four 55 male