I would like to plot the result of the values_counts()
method with seaborn
, but when I do so, it only shows one of the variables.
df = pd.DataFrame({"A":['b','b','a','c','c','c'],"B":['a','a','a','c','b','d']})
counts = df.A.value_counts()
sns.barplot(counts)
I want a barplot showing heights of 'a' = 1, 'b' = 2, 'c' = 3
I've tried renaming the index and passing in x
and y
parameters, but I cant' get it to work.
You can do this:
# Sorting indices so it's easier to read
counts.sort_index(inplace=True)
sns.barplot(x = counts.index, y = counts)
plt.ylabel('counts')
Note that using pandas.Series.plot
gives a very similar plot: counts.plot('bar')
or counts.plot.bar()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With