1

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:

  1. Occurence count per column, for example bar or any other plot where the values would be the value_counts() of the column
  2. The maximum values per column, for example - maximum values of columns A and B per category Language
  3. Sum of column 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.

1 Answer 1

1

Maximum values per language:

grouped_data = df.groupby('Language')[['A', 'B']].max().reset_index()
sns.barplot(x='Language', y='A', data=grouped_data)

enter image description here

sns.barplot(x='Language', y='B', data=grouped_data)

enter image description here

Sum of column A per category D:

sns.barplot(x='D', y='A', data=df.groupby('D').A.sum().reset_index())

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

And saving the outputs is plt.savefig('name.png') or sns_plot.savefig("output.png")?
@JonasPalačionis If you run ax = sns.barplot(x='Language', y='A', data=grouped_data) then you can save it with ax.get_figure().savefig('name.png')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.