ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

pandas众数mode()

2022-01-03 10:03:18  阅读:207  来源: 互联网

标签:legs NaN pandas mode 众数 2.0 wings axis


官方文档里的例子
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的众数 0 和 2。第二行中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

 

标签:legs,NaN,pandas,mode,众数,2.0,wings,axis
来源: https://www.cnblogs.com/xuwinwin/p/15758982.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有