codecademy-examples/aggregates/python-aggregatesIV.py
Jonathan Ervine 2ba94913fb new file: aggregates/a-b project/ad_click.csv
new file:   aggregates/a-b project/code.py
	new file:   aggregates/codecademy_code/script.py
	new file:   aggregates/codecademy_code/test1.py
	modified:   aggregates/orders.csv
	new file:   aggregates/python-aggregatesI.py
	new file:   aggregates/python-aggregatesII.py
	new file:   aggregates/python-aggregatesIII.py
	new file:   aggregates/python-aggregatesIV.py
	new file:   aggregates/python-aggregatesV.py
Added aggregate files
2020-03-17 17:02:38 +08:00

12 lines
297 B
Python

import pandas as pd
orders = pd.read_csv('orders.csv')
print(orders.head(10))
shoe_counts = orders.groupby(['shoe_type', 'shoe_color']).id.count().reset_index()
shoe_counts_pivot = shoe_counts.pivot(columns='shoe_color', index='shoe_type', values='id').reset_index()
print(shoe_counts_pivot)