Search⌘ K
AI Features

Read an SQLite File

Explore methods to read SQLite files using pandas, focusing on managing SQL DATE and INTEGER types. Learn how to convert date columns to pandas datetime objects using read_sql and sqlite3 connect parameters for accurate data operations.

We'll cover the following...

Try it yourself

Try executing the code below to see the result.

Python 3.8
import sqlite3
import pandas as pd
conn = sqlite3.connect(':memory:')
conn.executescript('''
CREATE TABLE visits (day DATE, hits INTEGER);
INSERT INTO visits VALUES
('2020-07-01', 300),
('2020-07-02', 500),
('2020-07-03', 900);
''')
df = pd.read_sql('SELECT * FROM visits', conn)
print('time span:', df['day'].max() - df['day'].min())

Explanation

SQLite3 is a great single-file database that is used many times to transfer data. It is widely used and heavily tested and can handle vast amounts of data up to 140 terabytes.

However, SQL does require some training.

In the teaser code, we create a hits table that has the ...