This release is a pre-release and may not be stable for production use.
pandasql
This is a fork of the original pandasql, with support of multiple SQL
backends and more convenient interface. See below for more info.
pandasql allows you to query pandas DataFrames using SQL syntax. It works
similarly to sqldf in R. pandasql seeks to provide a more familiar way of
manipulating and cleaning data for people new to Python or pandas.
Installation
$ pip install -U pandasql
Basics
In addition to the original pandasql's sqldf function this fork has
a class PandaSQL, which new users are encouraged to use.
PandaSQL Class
The class is more convenient when you need to perform multiple queries. PandaSQL takes 2 arguments:
db_uri: an optional SQLAlchemy connection string (defaults to in-memory SQLite database)persist: an optional boolean to determine if loaded tables are persisted in the database (holds connection open, default False)
sqldf Function
The main function used in pandasql is sqldf. sqldf accepts 3 parameters:
- an sql query string
- an optional SQLAlchemy connection string (defaults to in-memory SQLite database)
- an optional dict of session/environment variables (defaults to
**locals(),**globals())
Querying
pandasql uses SQLite syntax. Any pandas
dataframes will be automatically detected by pandasql. You can query them as
you would any regular SQL table.
$ python
>>> from pandasql import PandaSQL, load_meat, load_birth
>>> meat = load_meat()
>>> births = load_births()
>>> pdsql = PandaSQL()
>>> print pysqldf("SELECT * FROM meat LIMIT 10;").head()
date beef veal pork lamb_and_mutton broilers other_chicken turkey
0 1944-01-01 00:00:00 751 85 1280 89 None None None
1 1944-02-01 00:00:00 713 77 1169 72 None None None
2 1944-03-01 00:00:00 741 90 1128 75 None None None
3 1944-04-01 00:00:00 650 89 978 66 None None None
4 1944-05-01 00:00:00 681 106 1029 78 None None None
joins and aggregations are also supported
>>> q = """SELECT
m.date, m.beef, b.births
FROM
meats m
INNER JOIN
births b
ON m.date = b.date;"""
>>> joined = pyqldf(q)
>>> print joined.head()
date beef births
403 2012-07-01 00:00:00 2200.8 368450
404 2012-08-01 00:00:00 2367.5 359554
405 2012-09-01 00:00:00 2016.0 361922
406 2012-10-01 00:00:00 2343.7 347625
407 2012-11-01 00:00:00 2206.6 320195
>>> q = "select
strftime('%Y', date) as year
, SUM(beef) as beef_total
FROM
meat
GROUP BY
year;"
>>> print pysqldf(q).head()
year beef_total
0 1944 8801
1 1945 9936
2 1946 9010
3 1947 10096
4 1948 8766
More Info
More information and code samples available in the examples folder.
Metadata
Release files for pandas_query_sql 0.8.3.dev0
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 | |
|---|---|---|---|---|
| pandas_query_sql-0.8.3.dev0.tar.gz | 26.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pandas_query_sql-0.8.3.dev0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 51.7 kB
Release files / pandas_query_sql-0.8.3.dev0.tar.gz
| Download URL | pandas_query_sql-0.8.3.dev0.tar.gz |
|---|---|
| Size | 26.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f0152f91ec99c3e294fff447e8c5d92155db82977ad39bbdd0599aa38a119cc
|
|
BLAKE2b-256 checksum How to use checksums |
2c1a24d5b40bd31aa7e84a70c74037da2a19da6a799afe640f8b2225b2ada4c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / pandas_query_sql-0.8.3.dev0-py3-none-any.whl
| Download URL | pandas_query_sql-0.8.3.dev0-py3-none-any.whl |
|---|---|
| Size | 25.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0cb0a836dcb0eab6583f76f8a2eceb4b3eee849bc56013174b9256cdbad8479
|
|
BLAKE2b-256 checksum How to use checksums |
72d76c191585ee99d4ccacfe0fad7bd8b9dd9a68de4a530e8ca2fe1a9bedda61
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"44","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for pandas_query_sql 0.8.3.dev0
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.