Reading SQL data

Here we will be reading SQL data from the popular database browser that is SQLite which can be installed by executing the following command:

conda install sqlite

Then we will import the SQLite Python module as follows:

import sqlite3

Then, create a connection to the SQLite DB you want to read data from, as follows:

conn = sqlite3.connect("IMDB.sqlite")df = pd.read_sql_query("SELECT * FROM IMDB;", conn)df.head()

Next, pass the SQL query you want the data from to pandas with the read_sql_query method. The method reads the data and creates a DataFrame object, as shown in the following screenshot:

An SQLite database was used for ...

Get Mastering Exploratory Analysis with pandas now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.