Pandas Dataframe- How To Find Words That Repeat In Each Row
I have a dataframe with a text column containing long string values. The text has been cleaned and has only words as shown in the example below. text ===== This is the first row Th
Solution 1:
Convert the dataframe to a string, then you can do something like this:
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'
Post a Comment for "Pandas Dataframe- How To Find Words That Repeat In Each Row"