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
bettersql-1.3.0.tar.gz
(5.9 kB
view hashes)
Built Distribution
bettersql-1.3.0-py2-none-any.whl
(10.9 kB
view hashes)
Close
Hashes for bettersql-1.3.0-py2-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b81830caf9f7ffb9d712d6d086ac06350a6e073e5debbecc7de435c7a098b5d8 |
|
MD5 | ce35385cc1ec9a15b572f8422ac9770a |
|
BLAKE2b-256 | 649df02dfef1e12bf90c820191ce426301d72e42e4ee5d1b6228f75a9825712d |