1

I've got data in a pandas dataframe that looks like this:

ID    A    B    C    D
100   0    1    0    1
101   1    1    0    1
102   0    0    0    1
...

The idea is to create a barchart plot that shows the total of each (sum of the total number of A's, B's, etc.). Something like:

      X 
  X   X
x X   X 
A B C D

This should be so simple...

0

1 Answer 1

4

Set 'ID' aside, sum, and plot.bar:

df.set_index('ID').sum().plot.bar()

# or
df.drop(columns=['ID']).sum().plot.bar()

output:

enter image description here

just for fun

print(df.drop(columns='ID')
        .replace({0: ' ', 1: 'X'})
        .apply(sorted, reverse=True)
        .to_string(index=False)
     )

Output:

A B C D
X X   X
  X   X
      X
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.