Reputation: 4521
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.
Upvotes: 4
Views: 4115
Reputation: 51335
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()
Upvotes: 7