Reputation: 4842
I am new to Seaborn and Pandas
My DataFrame:
df
Search A B C D Language
Best TV for netflix 51 7.5 25.7 TV en
Best TV for firestick 42 6.3 34.77 TV es
TV cheap 32 2.7 69.33 Cheap en
Cheap TV 44 14.7 74.14 Best fr
...
I am learning to plot data with seaborn.
My goal is to be able to plot:
value_counts()
of the columnA
and B
per category Language
A
per category D
Should I first do calculations to get the numbers I need for the plots or are there more subtle ways of plotting pandas dataframes with seaborn as per seaborn documentation it is said that it was made to work well with pandas dataframes.
What I've tried
count = df['Language'].value_counts()
head = count.head(5)
sns.barplot(x=head, y=count, data=df)
plt.show()
Which plots the top5 language categories. But I don't know how to plot the second and third points in my goal section.
Thank you for your suggestions.
Upvotes: 1
Views: 294
Reputation: 10476
Maximum values per language:
grouped_data = df.groupby('Language')[['A', 'B']].max().reset_index()
sns.barplot(x='Language', y='A', data=grouped_data)
sns.barplot(x='Language', y='B', data=grouped_data)
Sum of column A per category D:
sns.barplot(x='D', y='A', data=df.groupby('D').A.sum().reset_index())
Upvotes: 1