Databases are extremely nice, especially when you want to handle a large amount of structured data.
Here is how to read a pandas DataFrame from an SQL database using the Pandas.read_sql() methods.
Here is the code
How to read data
Here we read the SQLite table and save it in a DataFrame format.
import pandas as pd import sqlite3 # Create the connection to the database con = sqlite3.connect("database.sqlite") # We execute the sql query against the database df = pd.read_sql("SELECT * from my_table", con, index_col="index") # We print the dataframe print(df.head()) # We close the connection con.close()
Here you are! You now know how to read a DataFrame from an SQLite Database.