0

Suppose I have a Dataframe

Product |   Price
------------------
    A   |   20
    B   |   10
    A   |   10
    B   |   15
    A   | 

How should I get the aggregated average values (excluding null values) and plot a graph.

A   | 15
B   | 12.5

So I would plot a graph for this table. I have though of using groupby but not sure how it would work for this scenarios.

2 Answers 2

1

Yes, you can use groupby and create a barplot after that:

import seaborn as sns

p_df = df.groupby('Product', as_index=False)['Price'].agg({'Avg':np.mean})

#barplot with seaborn
sns.barplot(p_df.Product, p_df.Avg)
Sign up to request clarification or add additional context in comments.

Comments

0

you can do groupby in the dataframe by

#lets suppose your dataframe is df
df.groupby('product').mean()

this will return you a new data frame

Comments

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.