0
votes

enter image description here

I have data like this. I would like to make a stacked bar chart where the x-axis is the ball color and each stack in the bar is the percentage of balls with that color that have that attribute (note each column in the bar chart will not sum to 100). I'm trying something like this

data = {'Ball Color' : ['Red', 'Blue', 'Blue', 'Red', 'Red', 'Red'],
   'Heavy?'  : [True, True, False, True, False, True],
   'Shiny?' : [True, True, False, True, True, False]}
code_samp = pd.DataFrame(data)
code_samp.groupby('Ball Color')[['Heavy?', 'Shiny?']].value_counts().plot.bar()

But value_counts is only supported for series. Any ideas? Thanks in advance

1
code_samp.groupby('Ball Color').sum().plot.bar() ?Scott Boston
Nice, that worked! Do you know if .sum() can express as a percentage?rollTech69

1 Answers

0
votes

Use:

code_samp.groupby('Ball Color').sum().plot.bar()

or

code_samp.groupby('Ball Color').mean().plot.bar()