Skip to content
This repository has been archived by the owner on Oct 31, 2018. It is now read-only.

tomasd/pandas-sqlalchemy-pivot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pandas-sqlalchemy-pivot

Provides pivot functionality for databases. Pivot aggregates are created directly in the database. Reshaping into pivot is done in the pandas framework.

Usage

table.insert().execute(customer_id=1, yearmonth='201001', gender='male', price=10)
table.insert().execute(customer_id=2, yearmonth='201001', gender='male', price=5)
table.insert().execute(customer_id=3, yearmonth='201001', gender='female', price=10)

select = sqlalchemy.select(table.c.yearmonth, table.c.gender, table.c.price)

table = pivots.pivot_table_from_select(
            select,
            rows='yearmonth', cols='gender', values='price'
        )

print table

Outputs:

            price
gender     female  male
yearmonth
201001         10    15

For more examples look at tests.

Similar projects

Similar project for postgresql is Mali Akmanalp's https://github.com/makmanalp/sqlalchemy-crosstab-postgresql

About

Pivot tables for sqlalchemy

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages