如何打乱 Spark 数据帧中的行? [英] How to shuffle the rows in a Spark dataframe?

查看:20
本文介绍了如何打乱 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?

推荐答案

需要使用dataframe的orderBy方法:

You need to use orderBy method of the dataframe:

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆