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

How do i display in plot sum values that match a given condition

I have like a DataFrame with tables of diff values.
Suppose like i have this data

Fruits   Volume

Apple    120
Peach    340
Apple    400
Apple    21
Peach    45
etc...   ...

How do i group fruits up, so my plot would not look like picrelated?
my outcome

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

>Solution :

You can try first sorting your dataframe by the column you want to group:

df = df.sort_values("Fruits")

and then when you plot (e.g with seaborn) specify the color based on the group:

import seaborn as sns
sns.barplot(data=df, x="label", y="Volume", hue="Fruits")
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