I have a dataframe with the following columns:
gender class
male A
female A
male B
female B
male B
female A
I want to plot a double bar graph with the columns as each gender and the values as the count of how many of each gender are in class A vs B respectively.
So the bars should be grouped by gender and there should be 2 bars - one for each class.
How do I visualize this? I see this example but I'm really confused
speed = [0.1, 17.5, 40, 48, 52, 69, 88]
lifespan = [2, 8, 70, 1.5, 25, 12, 28]
index = ['snail', 'pig', 'elephant',
'rabbit', 'giraffe', 'coyote', 'horse']
df = pd.DataFrame({'speed': speed,
'lifespan': lifespan}, index=index)
speed lifespan
snail 0.1 2.0
pig 17.5 8.0
elephant 40.0 70.0
rabbit 48.0 1.5
giraffe 52.0 25.0
coyote 69.0 12.0
horse 88.0 28.0
ax = df.plot.bar(rot=0)
My index is just row 0 to the # of rows, so I'm confused how I can configure df.plot.bar to work with my use case. Any help would be appreciated!


