【发布时间】:2020-10-10 18:41:13
【问题描述】:
我有一个数据框,我想向它添加一个列,该列将指示单词“yes”是否在该行文本列中(如果单词在该行中,则为 1,如果不是,则为 0) 仅当“是”作为单词而不是子字符串出现时,我才需要检查 1 或者如果“是”在标点符号旁边(例如:是!) 我怎么能在火花中做到这一点? 例如:
id group text
1 a hey there
2 c no you can
3 a yes yes yes
4 b yes or no
5 b you need to say yes.
6 a yes you can
7 d yes!
8 c no&
9 b ok
结果将是:
id group text check
1 a hey there 0
2 c no you can 0
3 a yes yes yes 1
4 b yes or no 1
5 b you need to say yes. 1
6 a yes you can 1
7 d yes! 1
8 c no& 0
9 b ok 0
【问题讨论】:
-
您想要纯火花解决方案,还是 SQL 解决方案适合您?
-
如果可以的话,都可以
标签: python sql dataframe pyspark apache-spark-sql