Created
April 12, 2023 15:41
-
-
Save srang992/257325d6e7e79f12260b446fe6a2b36e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plotly.express as px | |
import plotly.graph_objects as go | |
# removing those chocolates which has a count less than 10 | |
choco_data_with_count = count_df(choco_data, 'bar_name') | |
choco_data_mod = choco_data_with_count[choco_data_with_count['count'] >= 10] | |
# grouping chocolates according to bar_name and calculating mean | |
avg_rating_by_bar = choco_data_mod.groupby('bar_name')['rating'].mean() | |
avg_rating_by_bar_df = avg_rating_by_bar.rename_axis('bar_name').reset_index(name='rating') | |
avg_rating_by_bar_df_sorted = avg_rating_by_bar_df.sort_values(by='rating',ascending=False).head(10) | |
# plotting the results | |
fig = px.bar(avg_rating_by_bar_df_sorted, x='bar_name', y='rating', log_y=True, color_continuous_scale='viridis', color='rating') | |
fig.update_layout(title={'text': 'Most Popular Chocolate Bar'}) | |
fig.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment