reeesh
reeesh

Reputation: 11

Pandas groupby multiple column then subplot

I have a simple issue that I would appreciate if someone can help me with

I'm grouping a dataframe by two columns to create a multiindex dataframe. Then, I want to create a bar plot for each each group:

df.groupby(['Teacher_name','Class_name'], sort = True).Student_ID.count()

Here is an image of the bar plots I'm looking for, i.e., a plot for each teacher with the number of students in each class.

click here to see the image of the barplots im looking for

Upvotes: 1

Views: 930

Answers (1)

Ismael EL ATIFI
Ismael EL ATIFI

Reputation: 2108

You should install plotly and use the wonderful plotly express like this :

import plotly.express as px
fig = px.histogram(df, x="Class_name", facet_col="Teacher_name")
fig.update_layout(autosize=False, width=600, height=300) # resize figure
fig.show()

enter image description here

Upvotes: 2

Related Questions