首页 > 解决方案 > 我有一个熊猫数据框,其中一列包含文本。我想获取出现在整列的每一行中的唯一单词列表

问题描述

import pandas as pd

r1=['i just got the count', 'come on hold on man']

df=pd.DataFrame(r1,columns=['text'])

所需的输出:

r1 = [['i','just','got','the', 'count'],['come','on','hold', 'man']

在第二行中,“on”重复两次,所需的输出只显示唯一的单词。

标签: pythonpandasdataframe

解决方案


尝试:

df['text'].str.split().apply(set)

输出:

0    {got, just, count, the, i}
1         {on, man, come, hold}
Name: text, dtype: object

推荐阅读