Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Rank in pandas

Shulou Source: shulou.com Published: 2022-06-01 02:59:35 09月22日 Update

Editor to share with you how to use Rank in pandas, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Rank

Rank is a ranking function that ranks the values of the original sequence according to the rules (from big to small, from small to big), and returns the ranking after the ranking.

For example, there is a sequence [1Magne7d5], which uses rank to rank from small to big, and returns [1mem4d3], which is the ranking position of each value in the previous sequence.

Usage:

Rank (axis=0, method: str = 'average', numeric_only: Union [bool, NoneType] = None, na_option: str =' keep', ascending: bool = True, pct: bool = False)

Parameter function:

(1) axis: row or column

(2) method: how to return the ranking. You can choose {'average',' min', 'max',' first', 'dense'}.

Method=average default setting: the same value occupies the top two, and you can't tell who is 1 and who is 2, then the median value is 1.5, and the following one is the third.

Method=max: two people tied for second place, and the next person is third.

Method=min: two people tied for 1st place, and the next person is 3rd.

Method=dense: two people tied for first place, and the next person is second place.

Method=first: the same value is set according to its relative position in the sequence

(3) ascending: positive order and reverse order

Rank the value_1 listed in df:

Df ['rank_1'] = df [' value_1'] .rank () df

The above is all the contents of the article "how to use Rank in pandas". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Sequence individual article same from small to big small location content ranking not much median function reverse order function parameter most that is way more knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MariaDB Huawei Shulou Technology NVidia