0

I have written the following piece of code:

df.groupby(['neighborhood'])['price'].mean()

However, I would like to order the 'price' column from highest to lowest average. How do I do this?

LeoGER
  • 355
  • 1
  • 8
  • The output of [`groupby`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.groupby.html) is by default sorted by the keys (look at the `sort` argument). Your code returns a Series, so you want to chain on a `.sort_values(ascending=False)`, which sorts output Series by value. – ALollz Sep 21 '19 at 19:01
  • you need to add sort_values to your code. Here is an example: df.groupby(['neighborhood']) ['price']. mean().sort_values(ascending=False) – Vishwas Sep 21 '19 at 19:06

0 Answers0