Home > Software engineering >  How to produce a multiple group bar chart based on a specific dataframe column
How to produce a multiple group bar chart based on a specific dataframe column

Time:03-01

I have a dataframe which has the following data:

Age A
5   True
5   True
10  False
15  False
15  True
20  False
25  True

How can I make a bar chart plot which has the values of the total number of rows in Age? So for example, 7 as the Y axis and the age as the X axis, with each Age having a True/False bar plot.

I would like something like this, however instead of it saying gender F/M, it does True/False, for each Age range:

enter image description here

CodePudding user response:

We can use enter image description here

Also we could use enter image description here

CodePudding user response:

Probably your want something like this:

count_df = df.groupby("Age").count()
plt.barh(count_df.index, count_df.A, label="False")

sum_df = df.groupby("Age").sum()
plt.barh(sum_df.index, sum_df.A, label="True")

plt.legend()

enter image description here

let me know if I get what you want or i misunderstood your problem.

  • Related