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降序排查看各维度最大值?

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

  • 相关阅读:
    让程序只有一个进程实例在运行
    HDFS写入和读取流程
    HBase技术详细介绍
    Eclipse下配置使用Hadoop插件
    Hadoop节点热拔插
    剖析为什么在多核多线程程序中要慎用volatile关键字?
    MapReduce 模式、算法和用例(MapReduce Patterns, Algorithms, and Use Cases)
    并行编程中的“锁”难题
    配置 eclipse 编译、开发 Hadoop(MapReduce)源代码
    HBASE松散数据存储设计初识
  • 原文地址:https://www.cnblogs.com/xuwinwin/p/15758982.html
Copyright © 2011-2022 走看看