【问题标题】:Append the count of the occurrence of the word in python Dataframe [duplicate]在python Dataframe中附加单词出现的计数[重复]
【发布时间】:2020-12-12 14:31:29
【问题描述】:

我的原始数据

我想将文本数据转换为包含 500 个单词的数据框,如下图所示,其中每个句子都包含该单词在特定句子中的出现(数据框的行)。

最终输出数据

我已经使用 NLTK 执行了文本预处理。

【问题讨论】:

标签: python pandas dataframe nlp


【解决方案1】:
from sklearn.feature_extraction.text import CountVectorizer
count_vect = CountVectorizer()
X_train_counts = count_vect.fit_transform(twenty_train.data)  

https://scikit-learn.org/stable/tutorial/text_analytics/working_with_text_data.html

【讨论】:

  • 这只会形成一个向量矩阵。但我不想那样。我想获取数据框中句子中每个单词的出现次数。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-06-01
  • 2023-04-04
  • 1970-01-01
  • 2023-04-03
  • 2018-10-16
  • 1970-01-01
  • 2019-07-31
相关资源
最近更新 更多