我有很多头衔。我想在整个数据集中计算每个标题。例如:
`title`
A
b
A
c
c
c
输出:
title fre
A 2
b 1
c 3
您可以groupBy
title
然后count
:
import pyspark.sql.functions as f
df.groupBy('title').agg(f.count('*').alias('count')).show()
+-----+-----+
|title|count|
+-----+-----+
| A| 2|
| c| 3|
| b| 1|
+-----+-----+
或更简而言之:
df.groupBy('title').count().show()
+-----+-----+
|title|count|
+-----+-----+
| A| 2|
| c| 3|
| b| 1|
+-----+-----+
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句