I have a dataframe like this:
The dataframe is made by a groupby function and thereafter I have reset the index.
I'm trying to make a barplot with each score/grade grouped by gender. Thus 4 groups of bars.
With this code I don't get the desired output.
data_gender.plot(x='gender',kind='bar', stacked=False)
Asked
Active
Viewed 220 times
0

Matthew101
- 11
- 2
-
[SO How to create a grouped bar plot](https://stackoverflow.com/questions/47796264/how-to-create-a-grouped-bar-plot) may help you. – MagnusO_O Sep 05 '22 at 14:52
1 Answers
0
You could transpose your DF and use gender as index. try something like this:
import pandas as pd
import matplotlib.pyplot as plt
d = {'cat1': [4, 6], 'cat2': [8, 5], 'cat3': [3, 2]}
gender = ['female', 'male']
df = pd.DataFrame(data=d, index=gender).T
df.plot.bar()
plt.show()
Which yields:

MaxK
- 73
- 7