在列之间使用 spark-sql 或 pyspark 模式匹配进行转换
Transformation using either spark-sql or pyspark pattern matching between columns
我有一个问题声明所有列类型都是字符串
A 列模式如果它在 C 列中匹配,则将 Good Stuff 更新为 1,否则 (-)
pyspark、sparksql 中的任何查询
谢谢
阿努古普塔
如果我对你的问题的理解正确,这应该对你有用:
from pyspark.sql.functions import col, when
df.withColumn('Good Stuff', when(col('RouteTypeRankFinal').startsWith(col('Text(RouteRank)')), lit(1)).otherwise(lit('-')))
我有一个问题声明所有列类型都是字符串
A 列模式如果它在 C 列中匹配,则将 Good Stuff 更新为 1,否则 (-)
pyspark、sparksql 中的任何查询
谢谢 阿努古普塔
如果我对你的问题的理解正确,这应该对你有用:
from pyspark.sql.functions import col, when
df.withColumn('Good Stuff', when(col('RouteTypeRankFinal').startsWith(col('Text(RouteRank)')), lit(1)).otherwise(lit('-')))