为什么是这部分 (~F.col('text').rlike('\bfoo\b')
不起作用?
更新时间:
import pyspark.sql.functions as F
df = spark.createDataFrame(['Some text with foo and more text','Some text with bar and more text'],['value_1',None], "string").toDF("text", "check")
df_new = df.withColumn('check', F.when(((F.col('text').isNotNull()) & \
(F.col('check').isNull() & \
(~F.col('text').rlike('\bfoo\b')),
my_udf(F.col('text'))) \
.otherwise(F.col('check'))
df_new.show(truncate=False)
+----------------------------------------+
|text |check |
+--------------------------------+-------|
|Some text with foo and more text|value_1|
|Some text with bar and more text| |
+--------------------------------+-------+
1条答案
按热度按时间trnvg8h31#
尝试
rlike
而是使用正则表达式:没有必要使用
when
在这里,rlike/like
已返回布尔值。