我想用某种位表示法替换数据框中的值
id val1 val1
first 2 4
second 3 2
third 4 2
val rowsRdd: RDD[Row] = sc.parallelize(
Seq(
Row("first", 2, 4),
Row("second", 3, 2),
Row("third", 4, 2)
)
)
val schema = new StructType()
.add(StructField("id", StringType, true))
.add(StructField("val1", DoubleType, true))
.add(StructField("val2", DoubleType, true))
val df = spark.createDataFrame(rowsRdd, schema)
我必须这样替换2,3,4数字
2-0,1,1,1
3-0,0,1,1
4-0,0,0,1
我想得到
id val1 val2
first 2-0,1,1,1 4-0,0,0,1
second 3-0,0,1,1 2-0,1,1,1
third 4-0,0,0,1 2-0,1,1,1