Skip to content
Advertisement

count plot for each categorical variable

I have a dataset as below, where Q1,Q2,Q3 are categorical.

JavaScript

How can I plot the x axis for each column, and y as the count of the value for each column, all in one plot.

Sample out put

enter image description here

Advertisement

Answer

You can use value_counts on the columns and then plot:

JavaScript

grouped by quartile

JavaScript

grouped by value

old answer

A quick way using pandas only is:

JavaScript

But this won’t be flexible for the colors/layout.

If you want a nice output, rework your dataframe as long format and use seaborn.catplot:

JavaScript

output: seaborn catplot

I used the following input:

JavaScript

combining both answers:

JavaScript

combined value_counts and seaborn

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement