1

My first post on stackoverflow + am very new to programming. Apologies in advance for any poor formatting and missing information. :)

I aggregated two columns in a csv file (one column of seller names, the other of transactional amounts) to find how much each seller has made in total:

seller_group = df.groupby(["seller"])
#Total amount each seller has made so far
seller_group.aggregate({'price_paid':np.sum})

I want to sort it in descending order to find who the top sellers are, so I tried this:

to_sort = seller_group.aggregate({'price_paid':np.sum})
to_sort(x)[::-1]

The result is a numpy series without the seller column and the prices are formatted strangely (for example, [5.00000e+00]). I'd like a result that looks like this, but with the price_paid column sorted: seller sums output

Any ideas?

4
  • seller_group.aggregate({'price_paid':np.sum}).sort_values(by="price_paid") ? Commented May 11, 2021 at 18:12
  • This is very close! However, the result is in ascending order instead of descending. Commented May 11, 2021 at 18:19
  • 1
    Pass ascending=False to sort_values. Commented May 11, 2021 at 18:20
  • Worked beautifully. Thank you! Commented May 11, 2021 at 18:22

1 Answer 1

1

Try .sort_values():

df_out = seller_group.aggregate({'price_paid':np.sum}).sort_values(by="price_paid", ascending=False)
Sign up to request clarification or add additional context in comments.

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.