zoukankan      html  css  js  c++  java
  • pandas众数mode()

    官方文档里的例子
    Examples
    -------- >>> df = pd.DataFrame([('bird', 2, 2), ... ('mammal', 4, np.nan), ... ('arthropod', 8, 0), ... ('bird', 2, np.nan)], ... index=('falcon', 'horse', 'spider', 'ostrich'), ... columns=('species', 'legs', 'wings')) >>> df species legs wings falcon bird 2 2.0 horse mammal 4 NaN spider arthropod 8 0.0 ostrich bird 2 NaN By default, missing values are not considered, and the mode of wings are both 0 and 2. The second row of species and legs contains ``NaN``, because they have only one mode, but the DataFrame has two rows.
    不负责任的翻译:默认不考虑缺失值,wings的众数 02。第二行中species和legs含有“NaN”,
    因为它们都仅有一个众数,但DataFrame 有两行,所以凑数补个NaN。
     
    >>> df.mode()
      species  legs  wings
    0    bird   2.0    0.0
    1     NaN   NaN    2.0
    
    Setting ``dropna=False`` ``NaN`` values are considered and they can be
    the mode (like for wings).
    不负责任的翻译:设置dropna='False',即考虑计算缺失值Nan的数量
    >>> df.mode(dropna=False)
      species  legs  wings
    0    bird     2    NaN
    
    Setting ``numeric_only=True``, only the mode of numeric columns is
    computed, and columns of other types are ignored.
    不负责任的翻译:设置参数numeric_only=True,即仅统计数字的众数
    >>> df.mode(numeric_only=True)
       legs  wings
    0   2.0    0.0
    1   NaN    2.0
    
    To compute the mode over columns and not rows, use the axis parameter:
    不负责任的翻译:通过设置axis轴参数,可以选择统计行或列
    axis='columns'或axis='index'

    发现axis=0或axis=1也可以
    
    
    >>> df.mode(axis='columns', numeric_only=True)
               0    1
    falcon   2.0  NaN
    horse    4.0  NaN
    spider   0.0  8.0
    ostrich  2.0  NaN

     发现个有趣的规律: 随机设置不重复randint, mode后各列(或行)升序排序

    有什么用?当数据无缺失值且唯一,可以一键查看各维度的最小值,或sort_index降序排查看各维度最大值?

    但是行标变化感觉没什么用(摊手)

  • 相关阅读:
    精彩回顾 | Serverless Developer Meetup 12.04 深圳站
    Dubbo3 Triple 协议简介与选型思考
    阿里云 FaaS 架构设计与创新实践
    KubeDL 0.4.0 Kubernetes AI 模型版本管理与追踪
    shell脚本awk的用法
    case用法ping命令脚本(工作中常用的)
    linux时间与internet时间同步
    bootStrap表单验证插件的使用
    状态模式之观察者模式
    20211125
  • 原文地址:https://www.cnblogs.com/xuwinwin/p/15758982.html
Copyright © 2011-2022 走看看