[英]How to populate a Spark DataFrame column based on another column's value?
[英]How to make a column based on another column's value?
我有一个称为code
的列,此列包含2个字母值。 我想做的是创建另一个名为with_j
列,在该列中,我希望所有以j结尾的代码。 但是,与其说实际的代码,不如说: *j
所以看起来像这样:
之前:
code
bx
aj
dj
la
后
code with_j
bx
aj *j
dj *j
la
有办法吗?
使用endsWith
和when/otherwise
实际上非常简单。
Seq("bx", "aj", "dj", "la")
.toDF("code")
.withColumn("with_j",
when('code endsWith "j", "*j").otherwise("")
)
.show
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.