Skip to main content

A simple way to run SQL queries (SQLite3) on pandas.Dataframe objects.

Project description

SQLDF - Structured Query Language (SQL) on DataFrames (DF)

A simple wrapper to run SQL (SQLite) queries on pandas.DataFrame objects (Python).


  • 'python' >= 3.5
  • 'pandas' >= 1.0


With pip (from PyPI repository):

pip install sqldf

Examples of use

  • SELECT query with WHERE condition
# Import libraries
import pandas as pd
import numpy as np
import sqldf

# Create a dummy pd.Dataframe
df = pd.DataFrame({'col1': ['A', 'B', np.NaN, 'C', 'D'], 'col2': ['F', np.NaN, 'G', 'H', 'I']})

# Define a SQL (SQLite3) query
query = """

# Run the query
df_view =
  • UPDATE query that change inplace a pd.Dataframe
# Import libraries
import pandas as pd
import sqldf

# Create a dummy pd.Dataframe
url = ('')
tips = pd.read_csv(url)

# Define a SQL (SQLite3) query
query = """
SET tip = tip*2
WHERE tip < 2;

# Run the query

How it works

  1. It create a virtual in-memory SQLite3 database at runtime
  2. It convert the pd.DataFrame input(s) to SQL table(s)
  3. It proceed the SQL query on the table(s)
  4. It convert back the SQL table(s) to updated pd.DataFrame(s) if required
  5. It returns the result of the query if required

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqldf-0.4.2.tar.gz (4.5 kB view hashes)

Uploaded source

Built Distribution

sqldf-0.4.2-py3-none-any.whl (4.3 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page