我正在使用 Spark v1.6。我有以下两个数据帧,我想在我的左外连接 ResultSet 中将 null 转换为 0。有什么建议?
数据帧
val x: Array[Int] = Array(1,2,3)
val df_sample_x = sc.parallelize(x).toDF("x")
val y: Array[Int] = Array(3,4,5)
val df_sample_y = sc.parallelize(y).toDF("y")
左外连接val df_sample_join = df_sample_x
.join(df_sample_y,df_sample_x("x") === df_sample_y("y"),"left_outer")
结果集scala> df_sample_join.show
x | y
--------
1 | null
2 | null
3 | 3
But I want the resultset to be displayed as.
-----------------------------------------------
scala> df_sample_join.show
x | y
--------
1 | 0
2 | 0
3 | 3
最佳答案
只需使用 na.fill
:
df.na.fill(0, Seq("y"))
关于scala - 如何在 SPARK 数据帧 v1.6 的左外连接中将 NULL 替换为 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40772209/