Home > Blockchain >  How to created a stacked histogram from a dataframe for two related columns?
How to created a stacked histogram from a dataframe for two related columns?

Time:07-11

I have a data frame that looks like this -

License_type | User
A1           |  U1
A2           |  U1
A2           |  U1
A2           |  U1
A3           |  U1
A4           |  U1
A1           |  U2
A2           |  U2
A2           |  U2
A2           |  U2
A2           |  U3
A4           |  U3

I want to create a stacked histogram where for each User, the licenses types are stacked...

example

CodePudding user response:

You can use Pandas' crosstab to create the counts, then plot.bar:

pd.crosstab(df['User'], df['License_type']).plot.bar(stacked=True)    

Output:

enter image description here

CodePudding user response:

I use seaborn for my data visualisation. bar plot

  • Related