python - 我有一个熊猫数据框,其中一列包含文本。我想获取出现在整列的每一行中的唯一单词列表
问题描述
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”重复两次,所需的输出只显示唯一的单词。
解决方案
尝试:
df['text'].str.split().apply(set)
输出:
0 {got, just, count, the, i}
1 {on, man, come, hold}
Name: text, dtype: object
推荐阅读
- http - Go 上下文处理程序是否有任何方法可以检测底层连接(客户端)已经消失而没有完全读取请求正文
- opencv - 自训练 HAAR 分类器导致令人失望的低准确率
- http - 将文件中的 GET 参数解析为 Go 中的 NewRequest 调用
- python - 我们有什么方法可以在 sklearn 中使用重心进行局部线性嵌入吗
- mysql - 每小时创建一个具有唯一名称的新列
- three.js - 如何在三反应纤维中从画布中获取所有 Object3D
- node.js - 为什么MongoClient返回404
- performance - 卡夫卡消费者滞后与fluntd
- r - Adding text on each bar in horizontal bar plot in ggplot
- google-sheets - 如何在 Google 表格中批量编辑条件格式规则?