SQLtoPandas:
Use SQL queries on Pandas DataFrames.
Are you comfortable with SQL but not Pandas? Or maybe you're comfortable with Pandas but not SQL? Well, this library allows querying of Pandas DataFrames using SQL syntax. Hopefully it will let you learn SQL if you already understand Pandas, or learn how Pandas DataFrames behave if you already know SQL.
Unlike pandasql, this package does not create a local sqlite3 data on the users computer and query from that. Rather, it converts SQL commands directly into pandas code.
Usage:
Example usage:
>>> import sqltopandas
>>> spd = sqltopandas.SQLtoPD()
>>> df = pd.DataFrame(np.array([[1, 1, 3], [5, 5, 6], [7, 8, 9]]),columns=['a', 'b', 'c'])
>>> df
a b c
0 1 1 3
1 5 5 6
2 7 8 9
>>> spd.parse(df, 'SELECT a, b FROM df')
a b
0 1 1
1 5 5
2 7 8
>>> spd.parse(df, """SELECT a, b FROM df
... WHERE a!=1; """)
a b
1 5 5
2 7 8
>>> spd.parse(df, """SELECT a, b, c FROM df;
... ORDER BY a DESC;
... LIMIT 2;""")
a b c
2 7 8 9
1 5 5 6
>>> spd.parse(df, """SELECT COUNT(a) FROM df
... WHERE a=1 OR c=6; """)
2
Obvious edge cases
DataFrame column names, as well as DataFrame names, cannot be SQL keywords. For example, a column name with "SELECT" or "select" will throw an error.
Syntactical Rules
SQL tends to be quite lax with syntax. However, this library is not. Each SQL statement must end with a ;. If it does not, it will not be parsed correctly. For example, SELECT ... FROM ... WHERE; is one statement, as we define which columns and rows to select, which DataFrame to select them from. Think of each statement as being a complete mathematical expression. SELECT ... FROM ...; WHERE ...; is an incorrect statement because WHERE does not have a reference. This rules may change as the package is updated, so visit this page for the most updated documentation.
Contributing:
If you have read this far I hope you've found this tool useful. I am always looking to learn more and develop as a programmer, so if you have any ideas or contributions, feel free to write a feature or pull request.
Metadata
Release files for sqltopandas 0.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 |
|---|---|---|---|---|
| sqltopandas-0.2.tar.gz | 11.3 kB | Without provenance | Details for sqltopandas-0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sqltopandas-0.2-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for sqltopandas-0.2-py2.py3-none-any.whl |
Total release size: 23.2 kB
Release files / sqltopandas-0.2.tar.gz
| Download URL | sqltopandas-0.2.tar.gz |
|---|---|
| Size | 11.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
376c17f70bd75489305f7a70ce704726d9a19533605268788417dd645a056479
|
|
BLAKE2b-256 checksum How to use checksums |
816238738ade5a7c6c9949732d54f75b14bd31cd91038d2864b649692f083c9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.5
|
Release files / sqltopandas-0.2-py2.py3-none-any.whl
| Download URL | sqltopandas-0.2-py2.py3-none-any.whl |
|---|---|
| Size | 11.8 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
e51a8db953849111c631d2c66a85fe2a31bb6e91d7bbcf87d91537ebf33701c3
|
|
BLAKE2b-256 checksum How to use checksums |
325440b06e95a063ae7da2cb6c3aeaa8766ea882f873453d7d2ba3ce02853c5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.5
|
Security for sqltopandas 0.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.