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)
- More examples in the notebook: Demonstration notebook for SQLDF
How it works
- It create a virtual in-memory SQLite3 database at runtime
- It convert the pd.DataFrame input(s) to SQL table(s)
- It proceed the SQL query on the table(s)
- It convert back the SQL table(s) to updated pd.DataFrame(s) if required
- It returns the result of the query if required
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sqldf-0.4.2.tar.gz | 4.5 kB | Without provenance | Details for sqldf-0.4.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqldf-0.4.2-py3-none-any.whl | Python 3 | none | any | Details for sqldf-0.4.2-py3-none-any.whl |
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
|
Security for sqldf 0.4.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.