gpt4 book ai didi

scala - 如何重新整理Spark数据框中的行?

转载 作者:行者123 更新时间:2023-12-04 01:28:50 25 4
gpt4 key购买 nike

我有一个这样的数据框:

+---+---+
|_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整理所有行。

在不返回RDD的情况下如何做到这一点?

最佳答案

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

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

关于scala - 如何重新整理Spark数据框中的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43637625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com