How to sort a column in the pivot_table Pandas

Asked

Viewed 602 times

-3

Here’s the thing, I need to sort a pivot table to show me the values from highest to lowest.

impute_grps = df.pivot_table(values=["winPlacePerc"], 
                      index=["matchType"], 
                      aggfunc=np.count_nonzero)
print(impute_grps)

inserir a descrição da imagem aqui

I just want to sort out the values of this exit.

  • Please replace the image with characters that can be copied

  • If any answers solved your problem, you could mark one of the answers as accepted. Understand the importance of this link: https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-reply

1 answer

1


The output of the method pivot_table is a Dataframe, as can be seen in documentation. It is therefore sufficient to use the DataFrame sort_values. In your case:

impute_grps.sort_values(by = "winPlacePerc", ascending = False)

For more details, see the method documentation sort_values

Browser other questions tagged

You are not signed in. Login or sign up in order to post.