【发布时间】:2021-06-23 01:31:11
【问题描述】:
为什么这部分(~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| |
+--------------------------------+-------+
【问题讨论】:
标签: python-3.x apache-spark pyspark apache-spark-sql