python - Python 中的排名是什么?

标签 python python-3.x pandas rank

我对 Python 中的排名很好奇。如下所示的输出是如何到达的? 排名对数据做了什么?

Input obj = pd.Series([7,-5,7,4,2,0,4])

输出:

    print(obj)
    0    7
    1   -5
    2    7
    3    4
    4    2
    5    0
    6    4

排名

    print(obj.rank())
    0    6.5
    1    1.0
    2    6.5
    3    4.5
    4    3.0
    5    2.0
    6    4.5

最佳答案

According to the official Pandas Documentation ,它执行以下操作:

Compute numerical data ranks (1 through n) along axis. Equal values are assigned a rank that is the average of the ranks of those values

这意味着基本上所有的值都会被分配一个“高分”。值 7 是最高的,因此获得最高排名,但由于值 7 出现两次,它都获得高分 7 和 6。但是由于值 7 不能有 2 个不同的“高分”,它被分配的平均值两个排名。 (6+7)/2 是 6.5 -> 这是数据值 7 的排名。其他值更直接,例如 -5 是最低的,因此排名最差。

关于python - Python 中的排名是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51396389/

相关文章:

Python Pandas 在添加新列后将列标题添加为条目而不是实际数据

python - 您如何配置 Django 3 以与 MySql 5 一起使用?

python-3.x - Python pip install 未找到所需版本

python - 查找数据框中每一行的前 N ​​列

python-3.x - 如何使用内存有限的python处理两个或多个Big CSV文件?

python - 使用类和排序时,如何编写列表来更新文本文档?

python - 动态添加/覆盖property属性的setter和getter

python - spark python API java_gateway套接字连接错误

python - 两个连续的 yield 语句如何在 python 中工作?

python - 从字典列表创建 Pandas MultiIndex 的最佳方法是什么?