使用
set来创建唯一元素的序列。
进行一些清理
df以使小写字母的字符串分解:
df['text'].str.lower().str.split()Out[43]: 0 [my, nickname, is, ft.jgt]1 [someone, is, going, to, my, place]
该列中的每个列表都可以传递给
set.update函数以获取唯一值。使用
apply这样做:
results = set()df['text'].str.lower().str.split().apply(results.update)print(results)set(['someone', 'ft.jgt', 'my', 'is', 'to', 'going', 'place', 'nickname'])
或与
Counter()from注释一起使用:
from collections import Counterresults = Counter()df['text'].str.lower().str.split().apply(results.update)print(results)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)