Bar plot from dataframe, where x axis are column names and legend are indexes

ryszard eggink :

I have a dataframe as such:

Index                  A      C        D
Escheriecha coli       0.088  0.013   0.05
Human                  0.13   0.015   0.051
Candida                2.3    3.4     1.3

Now I want to make a barplot comparing those values. I want an x axis to be A, C, D and bar plots containing values in dataframe. I want bars to have different colours and legend, where we put values from indexes.

df.plot.bar()

makes exactly opposite, meaning x axis are indexes and legend is column names. Help appreciated

Craig :

You can transpose your dataframe to get the plot you want.

df.transpose().plot.bar()

Bar plot showing columns A, C, and D and labels based on disease

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=33132&siteId=1