[英]Copy data from one existing row to another existing row except 3 column in scala data frame
[英]Add one row from one Data set to Another Data set in Spark Scala
有兩個DataFrame集,一個是“訓練集”,另一個是“測試集”。 我想做的是通過使用“訓練集加上僅一行測試集”來迭代某些算法(讓我們稱之為AAA,需要RDD輸入格式),然后執行以下步驟。
實際上,在spark手冊中,我已經檢查了spark中的RDD和DataFrame是不可變的,因此無法使用
Testset.map( x => AAA(Trainset.union(x)) )
另外,我嘗試使用
Testset.map( x => AAA(Trainset.union(Array(x.get(0).toString.toDouble, x.get(1).toString.toDouble, ... x.get(19).toString.toDouble))
但是,它不起作用:(。是否有任何解決方案可以實現上述步驟?如果您對此問題有個好主意,請幫助我。
//修改並添加條件
由於耗時的問題,我需要使用並行計算。 因此,我無法使用“ for循環”。 謝謝。
不知道這是一個好主意,但是如何:
1)在訓練數據框上創建一個名為helper的新列,其值為-1
2)在測試數據框上創建一個名為helper的新列,如下所示:
test.withColumn("helper", monotonically_increasing_id())
3)將2)的輸出寫入磁盤以確保ID永不更改
4)並集1)和3)讀回,然后緩存/持久性/寫入磁盤並讀回
5)編寫一個循環,以過濾聯合的數據幀並執行以下邏輯:
val data = unioned.filter($"helper" === lit(-1) || $"helper" === lit(n))
val result = logic(data)
其中n是您要遍歷的值,從第一行測試的0開始
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.