计算数值列和字符串列的基本统计信息。
Syntax
describe(*cols: Union[str, List[str]])
参数
| 参数 | 类型 | 说明 |
|---|---|---|
cols |
str、list、optional | 要描述的列名或列名列表(默认为“所有列”)。 |
退货
DataFrame:一个新的数据帧,用于描述给定 DataFrame(提供统计信息)。
备注
此函数用于探索数据分析,因为我们不能保证生成的 DataFrame 架构的向后兼容性。
使用摘要展开统计信息并控制要计算的统计信息。
示例
df = spark.createDataFrame(
[("Bob", 13, 40.3, 150.5), ("Alice", 12, 37.8, 142.3), ("Tom", 11, 44.1, 142.2)],
["name", "age", "weight", "height"],
)
df.describe(['age']).show()
# +-------+----+
# |summary| age|
# +-------+----+
# | count| 3|
# | mean|12.0|
# | stddev| 1.0|
# | min| 11|
# | max| 13|
# +-------+----+
df.describe(['age', 'weight', 'height']).show()
# +-------+----+------------------+-----------------+
# |summary| age| weight| height|
# +-------+----+------------------+-----------------+
# | count| 3| 3| 3|
# | mean|12.0| 40.73333333333333| 145.0|
# | stddev| 1.0|3.1722757341273704|4.763402145525822|
# | min| 11| 37.8| 142.2|
# | max| 13| 44.1| 150.5|
# +-------+----+------------------+-----------------+