Skip to main content

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

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

Requirements

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

Installation

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 = """
SELECT *
FROM df
WHERE col_1 IS NOT NULL;
"""

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

# Create a dummy pd.Dataframe
url = ('https://raw.github.com/pandas-dev/pandas/master/pandas/tests/data/tips.csv')
tips = pd.read_csv(url)

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

# Run the query
sqldf.run(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

Release files for sqldf 0.4.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqldf 0.4.2
File Size Uploaded
sqldf-0.4.2.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqldf 0.4.2
File Interpreter ABI Platform
sqldf-0.4.2-py3-none-any.whl Python 3 none any Details

Total release size: 8.8 kB

Release files / sqldf-0.4.2.tar.gz

Download URL sqldf-0.4.2.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
5e8ed19f3ce2c8eb08fe9ea28afecfa1db50d94e035ab0f264df19ec006b100b
BLAKE2b-256 checksum
How to use checksums
e5fe7fcd0546dd9266d1ff136c573d184f05c7402a2b3c2f78ec02996208daaa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

Release files / sqldf-0.4.2-py3-none-any.whl

Download URL sqldf-0.4.2-py3-none-any.whl
Size 4.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
713e3bcce65d11658051b33a99e2504d8882cd254622344a3d6a3997cd18c641
BLAKE2b-256 checksum
How to use checksums
604b1a9f9f65bcc7cd8d724c700f469f9bbe3e796b3543e0d346e3e352a283d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2

Release history Release notifications | RSS feed

This release

0.4.2 This release

2 release files

0.3.6

2 release files

0.3.5

2 release files

0.3.4

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3

2 release files

0.2

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page