0

I have following dataframes:

      A   B.  C.    type
0     1   2   3    'house'
1     2   3   4    'dog'
2     3   4   5    'mom'

Basically, bar graph is created (ignore 'type) by grouping A, B, C together (x-axis looks like below).

ABC ABC ABC

However, what I want to create is like below (x-axis):

A(house)A(dog)A(mom) B(house)B(dog)B(mom) C(house)C(dog)C(mom)

But, by making house, dog, mom as legends.

Is this possible to generate bar graph like this?

sungjun cho
  • 809
  • 7
  • 18

1 Answers1

3

Try this:

>>> df
       A   B.   C.     type
0.0  1.0  2.0  3.0  'house'
1.0  2.0  3.0  4.0    'dog'
2.0  3.0  4.0  5.0    'mom'
>>> df.set_index('type').T.plot(kind = 'bar')
<matplotlib.axes._subplots.AxesSubplot at 0x1e5f8602548>

enter image description here

Sayandip Dutta
  • 15,602
  • 4
  • 23
  • 52