0
votes

I have a python dataframe with 10 columns. 2 of the columns (A and B) look like this:

A   B
y   n
y   y
y   nn
y   n
nn  y
n   nn
n   y
n   n
n   y
y   n
n   nn

I need to plot a grouped bar chart. The x-axis should have y, n and nn. The y-axis should have the counts of these three. I am not sure how to do this in case of categorical data. The empty rows for each column are different. Column A had 539 values and Column B has 480.

Any leads are appreciated.

Thanks.

2

2 Answers

0
votes

If you use pandas you can apply the method value_counts to each column then plot results:

df.apply(lambda x: x.value_counts()).plot.bar()

enter image description here

0
votes

You can also use seaborn on a melted data frame, but there might be something odd about your data frame such that the answer by @Mykola doesn't work:

import seaborn as sns
sns.countplot(x='value',hue='variable',data=df.melt())

enter image description here