Search code examples
pythonpandasdataframesorting

How to sort values in a DataFrame


I have some doubts. I get some result

poz = positiv[positiv["number"]>0].head(10)
poz

I got the output:

    number
abnormal    16
abolish 5
abominable  5
abomination 4
abort   1
aborted 6
abrasive    1
abrupt  6
abruptly    284
absence 10

But my result is alphabetical, how to sort so that it shows the most frequently used words. I tried using pd.nlargest but the result was the same as above.


Solution

  • Try with sort_values

    poz = poz.sort_values('number',ascending=False).head(10)