Skip to content

Instantly share code, notes, and snippets.

@srang992
Created April 13, 2023 03:33
Show Gist options
  • Save srang992/8e9477dea7257657e132dfe7e2357ac3 to your computer and use it in GitHub Desktop.
Save srang992/8e9477dea7257657e132dfe7e2357ac3 to your computer and use it in GitHub Desktop.
# removing those manufacturer whose count is less than 10
choco_data_with_sec_count = count_df(choco_data, 'manufacturer')
choco_data_mod2 = choco_data_with_sec_count[choco_data_with_sec_count['count'] > 10]
# grouping the data by manufacturer and calculating the avg. mean for each of them
avg_rating_by_company = choco_data_mod2.groupby('manufacturer')['rating'].mean()
avg_rating_by_company_df = avg_rating_by_company.rename_axis('Company').reset_index(name='Rating')
avg_rating_by_company_df_sorted = avg_rating_by_company_df.sort_values(by='Rating', ascending=False).head(10)
# adding title and plotting the data
fig = px.bar(avg_rating_by_company_df_sorted, x='Company', y='Rating', log_y=True, color_continuous_scale='inferno', color='Rating')
fig.update_layout(title={'text': 'The Best Chocolate Manufacturer'})
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment