小编Vic*_*ick的帖子

使用pyspark从每行的数组中获取不同的计数

我正在使用 pyspark 数据帧从每行的数组中寻找不同的计数:输入:col1 [1,1,1] [3,4,5] [1,2,1,2]

output:
1
3
2  

I used below code but it is giving me the length of an array:
output:
3
3
4

please help me how do i achieve this using python pyspark dataframe.

slen = udf(lambda s: len(s), IntegerType())
count = Df.withColumn("Count", slen(df.col1))
count.show()

Thanks in advanced !
Run Code Online (Sandbox Code Playgroud)

apache-spark apache-spark-sql pyspark pyspark-dataframes

1
推荐指数
1
解决办法
1134
查看次数