Skip to content

Instantly share code, notes, and snippets.

@vanessaaleung
Last active September 28, 2019 18:01
Show Gist options
  • Save vanessaaleung/1cdf852df3035fac0aefca862170de9d to your computer and use it in GitHub Desktop.
Save vanessaaleung/1cdf852df3035fac0aefca862170de9d to your computer and use it in GitHub Desktop.
num_top_venues = 10
indicators = ['st', 'nd', 'rd']
# create columns according to number of top venues
columns = ['Neighborhood']
for ind in np.arange(num_top_venues):
try:
# append 'st', 'nd', 'rd' to the top 3 venues
columns.append('{}{} Most Common Venue'.format(ind + 1, indicators[ind]))
except:
columns.append('{}th Most Common Venue'.format(ind + 1))
# create a new dataframe
neighborhoods_venues_sorted = pd.DataFrame(columns = columns)
neighborhoods_venues_sorted['Neighborhood'] = sf_grouped['Neighborhood']
for ind in np.arange(sf_grouped.shape[0]):
neighborhoods_venues_sorted.iloc[ind, 1:] = return_most_common_venues(sf_grouped.iloc[ind, :], num_top_venues)
neighborhoods_venues_sorted.head()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment