QPD (Query Pandas Dataframes) is a Python library that allows users to run SQL `SELECT` statements on pandas-like dataframes, including Pandas, Dask, and Ray (via Modin on Ray). It translates SQL directly into dataframe operations, prioritizing correctness and consistent behavior across backends, even handling SQL-specific behaviors like `GROUP BY` with null keys differently than default pandas. The current version is 0.4.4. The library has a sporadic but active release cadence, with multiple minor updates in recent history, primarily focusing on compatibility and bug fixes.
pip install qpdVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `qpd` to execute a SQL `SELECT` query on a Pandas DataFrame. It creates a sample DataFrame, defines a SQL query with `WHERE`, `GROUP BY`, `HAVING`, and `ORDER BY` clauses, and then uses `run_sql_on_pandas` to get the resulting DataFrame.
Be mindful of `NULL` handling in group keys. If specific Pandas-like null dropping behavior is desired, preprocess the DataFrame before passing it to `qpd` or post-process the `qpd` result.
Upgrade `qpd` to version 0.4.1 or higher when using Pandas 2.x or newer: `pip install qpd>=0.4.1`.
Upgrade `qpd` to version 0.2.4 or higher to avoid unintended side effects on input DataFrames: `pip install qpd>=0.2.4`.
Restrict SQL usage to `SELECT` statements for dataframe querying. For data modification or schema changes, use the native DataFrame API (Pandas, Dask, Ray).