【发布时间】:2018-07-29 21:50:10
【问题描述】:
使用 PySpark 数据帧,我正在尝试尽可能高效地执行以下操作。我有一个数据框,其中有一列包含文本和我想要过滤行的单词列表。所以:
数据框看起来像这样
df:
col1 col2 col_with_text
a b foo is tasty
12 34 blah blahhh
yeh 0 bar of yums
列表将是list = [foo,bar]
因此结果将是:
result:
col1 col2 col_with_text
a b foo
yeh 0 bar
之后不仅会进行相同的字符串匹配,还会使用 SequenceMatcher 左右测试相似性。这是我已经尝试过的:
def check_keywords(x):
words_list = ['foo','bar']
for word in x
if word == words_list[0] or word == words_list[1]:
return x
result = df.map(lambda x: check_keywords(x)).collect()
不幸的是,我没有成功,有人可以帮助我吗? 提前致谢。
【问题讨论】:
标签: python apache-spark dataframe pyspark