Reputation:
How to merge two groupby and sort_values in to one
df_most_ordered = online_rt.groupby(by=['Country']).sum()
df_most_ordered.sort_values(['Quantity'],ascending=False).iloc[1:11]
Upvotes: 1
Views: 335
Reputation: 642
You can perform the action in a same line by using the "."
df_most_ordered = online_rt.groupby(by=['Country']).sum().sort_values(['Quantity'],ascending=False).iloc[1:11]
Upvotes: 1
Reputation: 10476
You can use method chaining:
online_rt.groupby(by=["Country"]).sum().sort_values(
["Quantity"], ascending=False
).iloc[1:11]
Upvotes: 2
Reputation: 862511
Use .
for chaining both rows to one:
online_rt.groupby(by=['Country']).sum().sort_values(['Quantity'],ascending=False).iloc[1:11]
Upvotes: 1