官方文檔里的例子
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
發現個有趣的規律: 隨機設置不重復randint, mode后各列(或行)升序排序
有什么用?當數據無缺失值且唯一,可以一鍵查看各維度的最小值,或sort_index降序排查看各維度最大值?
但是行標變化感覺沒什么用(攤手)