本文介绍了如何重新整理Spark数据帧中的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的数据框:

I have a dataframe like this:

+---+---+
|_c0|_c1|
+---+---+
|1.0|4.0|
|1.0|4.0|
|2.1|3.0|
|2.1|3.0|
|2.1|3.0|
|2.1|3.0|
|3.0|6.0|
|4.0|5.0|
|4.0|5.0|
|4.0|5.0|
+---+---+

并且我想在Scala中使用Spark来对所有行进行洗牌.

and I would like to shuffle all the rows using Spark in Scala.

如何在不返回RDD的情况下执行此操作?

How can I do this without going back to RDD?

推荐答案

您需要使用数据框的orderBy方法:

You need to use orderBy method of the dataframe:

import org.apache.spark.sql.functions.rand
val shuffledDF = dataframe.orderBy(rand())

这篇关于如何重新整理Spark数据帧中的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 19:24