Skip to content

Instantly share code, notes, and snippets.

@Kiwibp
Created June 8, 2018 19:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kiwibp/c394655347458b03d5e4bdd23f96c8ac to your computer and use it in GitHub Desktop.
Save Kiwibp/c394655347458b03d5e4bdd23f96c8ac to your computer and use it in GitHub Desktop.
locations_ten_or_more = all_items_df.groupby(['Location']).filter(lambda g: g.Location.value_counts() >= 10) \
.loc[:,['Location','Description', 'Price', 'Title', 'Url']]
#checking the number of locations with less than 10 items
len_of_locs = len(locations_ten_or_more.groupby("Location").size())
print(f'There are {len_of_locs} cities with 10 items or more.')
print('\n')
#checking the locations with the most items in this subset
print('Locations with the most amount of items in this subset:')
print(locations_ten_or_more.groupby(['Location']).size().sort_values(ascending=False).head(11))
print('\n')
#sorting locations by largest total selling price
print('Locations with highest total selling price:')
print(locations_ten_or_more.groupby(['Location']).agg(['sum']).loc[:,'Price'].sort_values('sum', ascending=False).head(10))
print('\n')
#sorting locations by largest average selling price totals
print('Locations with highest average selling price:')
print(locations_ten_or_more.groupby(['Location']).mean().sort_values(by='Price',ascending=False).head(11))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment