A package to use SQL with Pandas DataFrames, list and dict.
Project description
A better SQL engine for DataFrames, Lists and Dictionaries!
Motivation
Pandasql is a great project but it lacked the ability to call Python UDF's or use SQL to update a DataFrame. Bettersql allows both of these features plus there is no need to define a lambda to pass globals() because I wrote the function to automatically get globals() from the caller level.
Installation
To install bettersql, simply:
$ pip install bettersql
Usage
A simple example:
from pandas import DataFrame
from bettersql import sqldf
def reverse(x):
# sample function with one parameter
if x is not None:
return x[::-1]
# DataFrame source
names = DataFrame({'id':[1, 2, 3], 'name':['Alpha', 'Beta', 'Gamma'], 'category':[1, 2, 2]})
# Dict of lists source
categories = {'id':[1, 2, 3], 'name':['One', 'Two', 'Three']}
sql = '''
SELECT n.id, n.name, n.category, c.name as categoryname, reverse(n.name) as reverse
FROM names AS n
LEFT JOIN categories AS c on n.category= c.id
'''
# The first reverse is the alias for the function in SQL and the second reverse is a reference to the Python UDF
r = sqldf(sql, reverse = reverse)
print(r)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file bettersql-1.3.2.tar.gz.
File metadata
- Download URL: bettersql-1.3.2.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/1.4.0 colorama/0.4.4 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cbdd61290006b66cc8ae7291db2660d25ae232323e78c4f1020d287bf632558a
|
|
| MD5 |
dc2bcf5329f211dfa27b429bc127eda6
|
|
| BLAKE2b-256 |
a6dd7da6aeadfff957a72a9dfa5c85881117c77168696e0fdf49fe9c2da0af52
|
File details
Details for the file bettersql-1.3.2-py3-none-any.whl.
File metadata
- Download URL: bettersql-1.3.2-py3-none-any.whl
- Upload date:
- Size: 11.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/1.4.0 colorama/0.4.4 CPython/3.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5edaff577f2ca47e1961b25a1ff4ede94a46a54df6061c2fdb0ed20355baef51
|
|
| MD5 |
0f104244bb7b149b704624acc40645c0
|
|
| BLAKE2b-256 |
8b1153e00f1ffe5a6ed52904c749304c30a928054420f396f2889882d0ac401b
|