我有一个包含长字符串值的文本列的dataframe。如下面的例子所示,文本已经被清除,并且只有单词。
text
=====
This is the first row
This is the second row
third row this is the 我想得到以下内容:
text
=====
first
second
third如何删除数据文件中每一行中出现的单词?
import pandas as pd
df = pd.DataFrame({'text': ['This is the first row','This is the second row', 'third row this is the']})
# what next?发布于 2020-09-27 08:54:21
将dataframe转换为字符串,然后可以执行以下操作:
text = 'This is the first row, This is the second row, This is the third row'
arr = [set(x.split()) for x in text.split(',')]
mutual_words = set.intersection(*arr)
result = [list(x.difference(mutual_words)) for x in arr]
result = sum(result, [])
final_text = (", ").join(result)
print(final_text)
# 'first, second, third'https://stackoverflow.com/questions/64086312
复制相似问题