Pandas DataFrame mode() 方法
定义和用法
mode()
方法返回每列的模式值。
均值、中位数和众数:
- 平均值 - 平均值
- 中位数 - 中点值
- 模式 - 最常见的值
通过指定列轴(axis='columns'
),mode()
方法会按列搜索并返回每行的模式值。
实例
返回每列的模式值:
import pandas as pd data = [[1, 1, 2], [6, 4, 2], [4, 2, 1], [4, 2, 3]] df = pd.DataFrame(data) print(df.mode())
语法
dataframe.mode(axis, numeric_only, dropna, kwargs)
参数
axis
、numeric_only
、dropna
参数是关键字参数。
参数 | 值 | 描述 |
---|---|---|
axis |
|
可选。要检查的轴。 默认为 0。 |
numeric_only |
|
可选。指定是否只检查数字值。 默认为 None。 |
dropna |
|
可选。指定是否删除 NULL 值。 默认为 True。 |
返回值
包含模式值的 DataFrame。
此函数不会对原始 DataFrame 对象进行更改。