PDX2: Helper functions to run SQL on Pandas DataFrames
NOTE: This is basically a clone of https://github.com/ajfriend/pdx (since pdx is already taken on PyPI.)
pip install pdx2
Small ergonomic improvements to make it easy to run DuckDB queries on Pandas DataFrames.
pdx2monkey-patchespandas.DataFrameto provide adf.sql(...)method.- since
pdxuses DuckDB, you can leverage their convienient SQL dialect:
Query a Pandas DataFrame with df.sql(...).
Omit the FROM clause because it is added implicitly:
import pdx2
iris = pdx2.data.get_iris() # returns pandas.DataFrame
iris.sql("""
select
species,
count(*)
as num,
group by
1
""")
You can use short SQL (sub-)expressions because FROM and SELECT * are implied whenever they're omitted:
iris.sql('where petal_length > 4.5')
iris.sql('limit 10')
iris.sql('order by petal_length')
iris.sql('') # returns the dataframe unmodified. I.e., 'select * from iris'
For more, check out the example notebook folder.
Other affordances
df.aslist()df.asdict()df.asitem()df.cols2dict()- save/load helpers for DuckDB database files
Reference
For bleeding edge DuckDB
git clone https://github.com/duckdb/duckdb.git
cd duckdb
../env/bin/pip install -e tools/pythonpkg --verbose
Metadata
Release files for pdx2 0.11.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pdx2-0.11.0.tar.gz | 5.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pdx2-0.11.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 13.5 kB
Release files / pdx2-0.11.0.tar.gz
| Download URL | pdx2-0.11.0.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
801bbf51fe736b9f78c56ff7383db6c6ceeeeb951b2ad466cafc643efa323b6c
|
|
BLAKE2b-256 checksum How to use checksums |
3ffb395567dfb388cce0a6435d25fefa43bfe1540f7fdb0f317aa360a3af2b40
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 24, 2025.
Transparency logRelease files / pdx2-0.11.0-py3-none-any.whl
| Download URL | pdx2-0.11.0-py3-none-any.whl |
|---|---|
| Size | 7.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5812bcc749fdb4a0c251c719da88192f992b03113c6f36e73dd7f4b1512e03b0
|
|
BLAKE2b-256 checksum How to use checksums |
cea0d8f4e5365003c70817faeac91437457829ce67c4ed357ca9f2486016b963
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.8
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 24, 2025.
Transparency log