how to plot the below groupby function on these 2 columns. I want to plot the result into a pie chart
tl = pd.unique(ddf['event_type'].tolist())
ct = ddf.groupby(['event_mohafaza','event_type']).aggregate('sum')
the result of the groupby function:
number_person
event_mohafaza event_type
loc1 camping 21
meeting 17
meeting 44
watch movie 25
loc2 meeting 33
stay at home 45
swimming 32
watch movie 55
loc3 stay at home 54
loc4 camping 27
swimming 12
loc5 watch movie 65
The problem is that the pie chart doesn't display
if i replace the groupby function by this statement ct = ddf["event_type"].value_counts()
the pie chart is displayed and the function works.
the code for ploting pie chart:
trace = go.Pie(labels=labels,
hoverinfo='label+percent',
values=ct,
textposition='outside',
rotation=90)
layout = go.Layout(
title="Percentage of events",
font=dict(family='Arial', size=12, color='#909090'),
legend=dict(x=0.9, y=0.5)
)
data = [trace]
print(data)
fig = go.Figure(data=data, layout=layout)
fig.show()