Skip to content

Instantly share code, notes, and snippets.

@srang992
Created April 13, 2023 04:05
Show Gist options
  • Save srang992/5eaae3748fc0c5bab4d66a2179b6f96b to your computer and use it in GitHub Desktop.
Save srang992/5eaae3748fc0c5bab4d66a2179b6f96b to your computer and use it in GitHub Desktop.
# filtering those chocolates which are manufactured by Soma Chocomaker
soma_choco_data = choco_data[choco_data['manufacturer'].isin(['Soma'])]
# creating the dictionary
bean_dict = {}
bean_origins = list(soma_choco_data['bean_origin'])
for origin in bean_origins:
if origin in bean_dict:
bean_dict[origin] += 1
else:
bean_dict[origin] = 1
# creating the dictionary
bean_dict = sort_sliced_dict(bean_dict, is_reverse=True, item_count=5)
# plotting the graph
fig = px.bar(x=list(bean_dict.keys()),
y=list(bean_dict.values()),
text=list(bean_dict.values()),
color_continuous_scale='inferno',
color=list(bean_dict.keys()))
fig.update_traces(textposition='outside')
fig.update_layout(title={'text': 'Beans providers for Soma'},
xaxis={'title_text': 'Beans Origin'},
yaxis={'title_text': 'Count'})
fig.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment