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

Time:11-13

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

CodePudding user response:

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")
  • Related