Skip to main content

Helper functions to run SQL on Pandas DataFrames

Project description

PDX2: Helper functions to run SQL on Pandas DataFrames

GitHub | PyPI

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.

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

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

pdx2-0.11.0.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pdx2-0.11.0-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file pdx2-0.11.0.tar.gz.

File metadata

  • Download URL: pdx2-0.11.0.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pdx2-0.11.0.tar.gz
Algorithm Hash digest
SHA256 801bbf51fe736b9f78c56ff7383db6c6ceeeeb951b2ad466cafc643efa323b6c
MD5 d63094f796d5b2d52b0f548802f9b0aa
BLAKE2b-256 3ffb395567dfb388cce0a6435d25fefa43bfe1540f7fdb0f317aa360a3af2b40

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdx2-0.11.0.tar.gz:

Publisher: pypi_publish.yml on ajfriend/pdx2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pdx2-0.11.0-py3-none-any.whl.

File metadata

  • Download URL: pdx2-0.11.0-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pdx2-0.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5812bcc749fdb4a0c251c719da88192f992b03113c6f36e73dd7f4b1512e03b0
MD5 b136a467fa3bb8d55edfbbb9affeeb21
BLAKE2b-256 cea0d8f4e5365003c70817faeac91437457829ce67c4ed357ca9f2486016b963

See more details on using hashes here.

Provenance

The following attestation bundles were made for pdx2-0.11.0-py3-none-any.whl:

Publisher: pypi_publish.yml on ajfriend/pdx2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page