简体   繁体   English

如何在Spark数据帧中混洗行?

[英]How to shuffle the rows in a Spark dataframe?

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|
+---+---+

and I would like to shuffle all the rows using Spark in Scala. 我想在Scala中使用Spark来洗牌所有行。

How can I do this without going back to RDD? 如何在不返回RDD的情况下完成此操作?

You need to use orderBy method of the dataframe: 您需要使用orderBy方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM