1

I have a Pandas DataFrame:

cols = ["A", "B", "C", "D", "E"]
values = [[True, True, True, False, False],
          [False, True, True, True, False], 
          [True, True, False, False, False], 
          [False, False, False, False, True]]

dummy_df = pd.DataFrame(values, columns=cols)
dummy_df

and

How will I plot this as a grouped bar chart using matplotlib? I want the result to look something like this...

enter image description here

1 Answer 1

2

You can coun each column in DataFrame.apply, transpose and call DataFrame.plot.bar:

cols = list('ABCDE')
values = [[True, True, True, False, False],
          [False, True, True, True, False], 
          [True, True, False, False, False], 
          [False, False, False, False, True]]

dummy_df = pd.DataFrame(values, columns=cols)
dummy_df.apply(pd.value_counts).T.plot.bar()

g

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.