博客
关于我
pandas.groupby().rank()用法详解
阅读量:339 次
发布时间:2019-03-04

本文共 2774 字,大约阅读时间需要 9 分钟。

  • pandas.DataFrame.groupby()

Group DataFrame using a mapper or by a Series of columns.

A groupby operation involves some combination of splitting the object, applying a function, and combining the results. This can be used to group large amounts of data and compute operations on these groups.

  • Parameters
  1. by : mapping, function, label, or list of labes

    Used to determine the groups for the groupby.

    If by is a function, it’s called on each value of the object’s index.

    If a dict or Series is passed, the Series or dict VALUES will be used to determine the groups.

    If an ndarray is passed, the values are used as-is determine the groups.

    A label or list of labels may be passed to group by the columns in self.

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

    Split along rows (0) or columns (1).

  3. level : int, level name, or sequence of such, default None

    If the axis is a MultiIndex (hierarchical), group by a particular level or levels.

  4. as_index : bool, default True

    For aggregated output, return object with group labels. Only relevant for DataFrame input. as_index=False is effectively ‘SQL-style’ grouped output.

  5. sort : bool, default True

    Sort group keys.

    Get better performance by turning this off. Note this does not influence the order of observations within each group.

    Groupby preserves the order of rows within each group.

  6. group_keys : bool, default True

    When calling apply, add group keys to index to identify pieces.

  7. squeeze : bool, default True

    Reduce the dimensionality of the return type if possible, otherwise return a consistent type.

  8. observed : bool, default False

    This only applies if any of the groupers are Categoricals.

    If True : only show observed values for categorical groupers.

    If False : show all values for categorical groupers.

  9. dropna : bool, default True

    If True, and if group keys contain NA values, NA values together with row/column will be dropped.

    If False, NA values will also be treated as the key in groups.

  • Returns

Returns a groupby object that contains information about the groups.

  • PANDAS.DATAFRAME.RANK

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

Computing 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.

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

How to rank the group of records that have the same value.

  1. average : average rank of the group
  2. min: lowest rank in the group
  3. max: highest rank in the group
  4. first: ranks assigned in order they appear in the array
  5. dense: like ‘min’, but rank always increases by 1 between groups.

method是针对rank排名讲的,指的是原始数据序列中存在相同的数据,这些相同数据返回的rank排名,如果是max就取相同数据所占顺序中最大的,min就是其中最小的。first就是按照他们在原始数据中所出现的顺序给定rank。

  • References

转载地址:http://zdge.baihongyu.com/

你可能感兴趣的文章
第六章 IIR数字滤波器的设计方法之三全通系统
查看>>
深度图像的获取原理
查看>>
kinect人体骨架25点
查看>>
密码学与计算机网络安全、信息安全与密码学、解决区块链隐私问题的密码学
查看>>
FANUC机器人R-30iB_R-30iB PLUS备件规格型号统计整理
查看>>
如何在VM station虚拟机中安装西门子博途TIA PORTAL?
查看>>
FANUC机器人的镜像备份操作及U盘格式化具体步骤
查看>>
vue-依赖-点击复制
查看>>
vue如何配置兼容ie es6转es5
查看>>
node-npm的简绍与使用
查看>>
js井子棋
查看>>
vue项目如何区分开发、生产和测试环境
查看>>
css取消双击选中文字
查看>>
LeetCode 116填充每个节点的下一个右侧结点指针
查看>>
C++小笔记——function绑定重载函数、私有继承用的条件
查看>>
最近一些算法题的总结
查看>>
2021-4-28【PTA】【L2-1 包装机 (25 分)】
查看>>
2021-5-2【指针】【作业】【指针代替下标进行数组编程】
查看>>