Home > OS >  Aggregating and plotting multiple columns using matplotlib
Aggregating and plotting multiple columns using matplotlib

Time:11-17

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...

CodePudding user response:

Set 'ID' aside, 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
  • Related