Home > database >  pandas, produce a multiple plot bar chart based on a specific column
pandas, produce a multiple plot bar chart based on a specific column

Time:02-28

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