Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Seaborn with multiple Columns

I have a dataframe data_gender:

gender math_score reading_score writing_score avg_score
female 63.63 72.61 72.47 69.57
male 68.73 65.47 63.31 65.84

and I want to make a seaborn barplot that looks like this plot that I made with matplotlib with simple line

data_gender.plot.bar(figsize=(8,6))

matplotlib bar plot

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How would one do it with seaborn?

>Solution :

You can reshape with melt and pass the data to sns.barplot:

sns.barplot(data=data_gender.melt(id_vars='gender',
                                  value_name='score', var_name='course'),
            x='gender', y='score', hue='course')

output:

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading