https://github.com/tomasd/pandas-sqlalchemy-pivot
Pivot tables for sqlalchemy
https://github.com/tomasd/pandas-sqlalchemy-pivot
Last synced: 11 months ago
JSON representation
Pivot tables for sqlalchemy
- Host: GitHub
- URL: https://github.com/tomasd/pandas-sqlalchemy-pivot
- Owner: tomasd
- Archived: true
- Created: 2012-09-22T09:14:49.000Z (almost 14 years ago)
- Default Branch: master
- Last Pushed: 2012-10-06T17:15:09.000Z (over 13 years ago)
- Last Synced: 2024-08-08T23:27:43.761Z (almost 2 years ago)
- Language: Python
- Homepage:
- Size: 117 KB
- Stars: 14
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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