将数据读取到PySpark数据后。我想找到两件事:
frequencies
我想知道的有效方法,。
示例:
Col1 | Col2
10 | abc
10 | xyz
10 | abc
90 | xyz
10 | abc
90 | xyz
90 | abc
10 | xyz
10 | abc
10 | xyz结果是-
For Col1,
最高频率值为10,90,频率分别为7,3。最大值为90,10。
同样,对于Col2也是如此。这是一个很小/很简单的例子。
My take:
记住,我想执行的动作越来越少。
逐列计算。对于Col1,
(dataframe.groupby('Col1').count()
.withColumn('rank_count', F.row_number().over(Window.orderBy('count')))
.withColumn('rank_value', F.row_number().over(Window.orderBy('Col1')))
.filter("rank_value <= 5 or rank_count <= 5").collect())然后从采集的输出中提取最终结果。
发布于 2020-11-03 15:02:36
为了在Col1中找到最常见的值,
dataframe.groupby(col('Col1')).agg(count('*').alias('frequency')\
.sort(col('frequency'),ascending=False).show(5,False)在Col1中的数据中查找前5种不同的值
dataframe.select('Col1').distinct().orderBy("Col1", ascending=False).show(5,False)https://stackoverflow.com/questions/64664674
复制相似问题