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

...
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())
...