3
$\begingroup$

I have been analysing seller data and trying to get insights. I have written a groupby statement to get the average price of selling for every seller

for seller,seller_df in g:

df=df.append({'Seller':seller,'AveragePrice':seller_df.Price.mean() }, ignore_index=True)
print(seller)
    df.sort_values(by='AveragePrice',ascending=False,inplace=True)
plt.figure(figsize=(15,30))
sns.barplot(data=df.dropna()[:100],y='Seller',x='AveragePrice')

The bar plot is only for the top 100 sellers and shows who has the max average selling price. Plot

I believe this method is inaccurate as I also should consider the amount of properties that he has sold in order to get the best seller. For e.g.: if A sold 20 houses with average 5 and B sold 200 with average 5, B should be the winner.So I have two questions:

  1. How can I incorporate this in my code?

  2. Can I optimise the code snippet?

I am a newbie and any help is appreciated. Please refer to this link for my Kaggle notebook. It does not contain the code posted here as I am doing the analysis locally but you can have a look at the data.

Dataset

$\endgroup$
12
  • $\begingroup$ datascience.stackexchange.com/q/29908/35644. This might help you to plot groupby pd, Also there is no link in your question, kindly edit it for the us to help you further.., it seems that you want to add the count also.... $\endgroup$
    – Aditya
    Commented May 29, 2018 at 19:50
  • $\begingroup$ I have no issues in plotting. What I am trying to ask is that I would consider a seller better than the other even if the average price at which they sell their houses are same if, the latter sells more houses. I want to know how to calculate this average by incorporating that count into my code here. I do not know how to do it. $\endgroup$
    – Shiny
    Commented May 29, 2018 at 23:28
  • $\begingroup$ You define a new metric and use that instead of 'AveragePrice' $\endgroup$
    – oW_
    Commented May 29, 2018 at 23:37
  • $\begingroup$ How do I do that in Pandas easily? I can use value_counts for the frequency of occurrence and use it. But I am unclear about the next steps. $\endgroup$
    – Shiny
    Commented May 29, 2018 at 23:45
  • 1
    $\begingroup$ which is better, average of 4 with 1000 sales compared to 5 average of say 50 sales? $\endgroup$ Commented May 30, 2018 at 4:55

1 Answer 1

0
$\begingroup$

For this kind of analysis, to calculate the total revenue of a seller as a feature seems sufficient, because it accounts for both amount of houses sold and house prices. Formula is the sum of all individual house prices sold.

df = seller_df.groupby(by='Seller')['Price'].sum().reset_index()

(Disclaimer: code untested)

$\endgroup$

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.