我试图从单词列表中返回一列新的“已找到”单词。我已经编写了代码,当找到单词时返回“T”。如何返回实际单词
我的单字:
[“谋杀”, "暴力",, “闪回”, "邪教",, “复仇”, “浪漫”, “喜剧”, “迷幻药”, "悬念",, “火车”]
目前:
from pyspark.sql.functions import col, when
df.select(
"*",
when(col("tags").rlike("|".join(list)), 'T').alias("toptags"),
).show()
+--------------------+-------+
| tags|toptags|
+--------------------+-------+
|cult, horror, got...| T|
| violence| T|
|they dream of som...| null|
| imdb| null|
|inspiring, romant...| T|
+--------------------+-------+
预期结果:
+--------------------+-------+
| tags|toptags|
+--------------------+-------+
|cult, horror, got...| cult |
| violence|violence|
|they dream of som...| null |
| imdb| null |
|inspiring, romant...|romance |
+--------------------+-------+
目前没有回答
相关问题 更多 >
编程相关推荐