pandas排名函数rank()的参数

       今天给一个python程序添加数据排名,需要使用pandas的rank()函数,使用时发现现排名输出跟自己预想的不太一样,随后在网上查了一下使用方法,发现很多网友介绍这个函数,有的写的异常详细,有的超级简略,最后又看了一下pandas上的说明文档,感觉学习函数最好的方法还是看官方说明文档。

下面代码中的参数,使用的都是默认参数,学习一个函数,不系统了解一下各种参数,上来直接用,就有可能出现意想不到的结果。

DataFrame.rank(axis=0, method='average', numeric_only=False, na_option='keep', ascending=True, pct=False)

Compute numerical data ranks (1 through n) along axis.

By default, equal values are assigned a rank that is the average of the ranks of those values.

     老外的排名习惯好象跟中国真不太一样。遇到相同的成绩,我们一般都是作为并列第几名,老外默认是把所有相同成绩占据的位次取平均数,真是挺有意思的。

Parameters:

axis:{0 or ‘index’, 1 or ‘columns’}, default 0

Index to direct ranking. For Series this parameter is unused and defaults to 0.

method:{‘average’, ‘min’, ‘max’, ‘first’, ‘dense’}, default ‘average’

How to rank the group of records that have the same value (i.e. ties):

  • average: average rank of the group

  • min: lowest rank in the group

  • max: highest rank in the group

  • first: ranks assigned in order they appear in the array

  • dense: like ‘min’, but rank always increases by 1 between groups.

numeric_only:bool, default False

        For DataFrame objects, rank only numeric columns if set to True.

        Changed in version 2.0.0: The default value of numeric_only is now False.

na_option:{‘keep’, ‘top’, ‘bottom’}, default ‘keep’

 How to rank NaN values:

  • keep: assign NaN rank to NaN values

  • top: assign lowest rank to NaN values

  • bottom: assign highest rank to NaN values

ascending: bool, default True

Whether or not the elements should be ranked in ascending order.

pct: bool, default False

Whether or not to display the returned rankings in percentile form.

Returns:

        same type as caller

        Return a Series or DataFrame with data ranks as values.

      

相关推荐

  1. pandas排名函数rank()参数

    2024-07-19 12:52:01       19 阅读
  2. 【MySQL】MySQL版本8+ 窗口函数 PERCENT_RANK 使用

    2024-07-19 12:52:01       49 阅读
  3. 【C++】简化for-range算法函数

    2024-07-19 12:52:01       58 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-19 12:52:01       67 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-19 12:52:01       72 阅读
  3. 在Django里面运行非项目文件

    2024-07-19 12:52:01       58 阅读
  4. Python语言-面向对象

    2024-07-19 12:52:01       69 阅读

热门阅读

  1. 智能结合:信息推送与供需发布机器人

    2024-07-19 12:52:01       21 阅读
  2. 2、SystemC基础语法

    2024-07-19 12:52:01       20 阅读
  3. 基于深度学习的水果识别系统

    2024-07-19 12:52:01       19 阅读
  4. C语言 条件编译

    2024-07-19 12:52:01       18 阅读
  5. 利用 PHP 解锁 1688 详情 API 接口的秘密

    2024-07-19 12:52:01       21 阅读
  6. Odoo创建一个自定义UI视图

    2024-07-19 12:52:01       23 阅读
  7. 代码随想录算法训练营第16天|二叉树part 04

    2024-07-19 12:52:01       23 阅读
  8. 华中师范大学学报人文社会科学版

    2024-07-19 12:52:01       25 阅读
  9. 动态规划练习题(2024/7/18)

    2024-07-19 12:52:01       20 阅读
  10. 计算机视觉8 图像增广

    2024-07-19 12:52:01       16 阅读
  11. Linux输出重定向详解

    2024-07-19 12:52:01       17 阅读
  12. ArduPilot开源代码之AP_DAL_RangeFinder

    2024-07-19 12:52:01       16 阅读
  13. 可视化页面LandingPage如何修改组件的内容 - Modstart

    2024-07-19 12:52:01       18 阅读