给出以下结构:
val df = Seq("Color", "Shape", "Range","Size").map(Tuple1.apply).toDF("color")
val df1 = df.withColumn("Success", when($"color"<=> "white", "Diamond").otherwise(0))
Run Code Online (Sandbox Code Playgroud)
我想再写一个WHEN条件,上面的条件是大小> 10,并且Shape列的值为Rhombus,然后将“ Diamond”值插入该列,否则为0。我尝试如下所示,但失败了
val df1 = df.withColumn("Success", when($"color" <=> "white", "Diamond").otherwise(0)).when($"size">10)
Run Code Online (Sandbox Code Playgroud)
请建议我仅使用scala的dataframe选项。带有sqlContext的Spark-SQL对我没有帮助。
谢谢 !