I have an issue writing query to pandas. I have a dataframe: (item_name, order_id, quantity, item_price1).
The task is to get the quantity sold of most expensive product. When I write the query like this:
df.groupby('item_name')['item_price1','quantity'].agg(['max','count'])
it works fine. But when I try to sort the result of the query to find the most expensive one using sort_values like this:
df.groupby('item_name')['item_price1','quantity'].agg(['max','count']).sort_values(by='max', ascending=False).head(10)
it ends with the error:
Key error 'max'
What will be the right thing to do?
dfwith a column calledmax? Can you confirm this?.sort_values(by=('item_price1', 'max'), ascending=False)?