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
This commit is contained in:
Jonathan Ervine
2020-03-17 17:02:38 +08:00
parent ea143ef778
commit 2ba94913fb
10 changed files with 1954 additions and 125 deletions
+7
View File
@@ -0,0 +1,7 @@
import codecademylib
import numpy as np
import pandas as pd
orders = pd.read_csv('orders.csv')
shoe_counts = orders.groupby(['shoe_type', 'shoe_color']).id.count().reset_index()
+18
View File
@@ -0,0 +1,18 @@
load_file_in_context('script.py')
try:
shoe_counts_pivot
except NameError:
fail_tests('Did you remember to define `shoe_counts_pivot`?')
ans = orders.groupby(['shoe_type', 'shoe_color']).id.count().reset_index()\
.pivot(columns='shoe_color', index='shoe_type', values='id')\
.reset_index()
if (set(ans.columns) - set(shoe_counts_pivot.columns)) == set(['shoe_type']):
fail_tests('Did you remember to use `reset_index()` after `pivot`?')
elif set(shoe_counts_pivot.columns) != set(ans.columns):
fail_tests('It looks like you have the wrong columns. You should have {}, but you have {}.'.format(
', '.join(ans.columns), ', '.join(shoe_counts_pivot.columns)))
pass_tests()