【问题标题】:Exporting relevant words TF-IDF TextBlob python导出相关词TF-IDF TextBlob python
【发布时间】:2015-11-04 17:38:35
【问题描述】:

我按照这个tutorial 在我的文档中搜索相关单词。我的代码:

>>> for i, blob in enumerate(bloblist):
print i+1
scores = {word: tfidf(word, blob, bloblist) for word in blob.words}
sorted_words = sorted(scores.items(), key=lambda x: x[1], reverse=True)
for word, score in sorted_words[:10]:
    print("\t{}, score {}".format(word, round(score, 5)))

1
 k555ld-xx1014h, score 0.19706
 fuera, score 0.03111
 dentro, score 0.01258
 i5, score 0.0051
 1tb, score 0.00438
 sorprende, score 0.00358
 8gb, score 0.0031
 asus, score 0.00228
 ordenador, score 0.00171
 duro, score 0.00157 
2
 frentes, score 0.07007
 write, score 0.05733
 acceleration, score 0.05255
 aprovechando, score 0.05255
 . . . 

这是我的问题,我想导出一个包含以下信息的数据框:索引、前 10 个单词(用逗号分隔)。我可以用熊猫数据框保存的东西。 示例:

TOPWORDS = pd.DataFrame(topwords.items(), columns=['ID', 'TAGS'])

提前谢谢大家。

【问题讨论】:

    标签: python text-mining tf-idf textblob


    【解决方案1】:

    解决了!

    这是我的解决方案,也许不是最好的,但它确实有效。

    tags = {}
    for i, blob in enumerate(bloblist):
          scores = {word: tfidf(word, blob, bloblist) for word in blob.words}
          sorted_words = sorted(scores.items(), key=lambda x: x[1], reverse=True)
          a =""
          for word, score in sorted_words[:10]:
               a= a + ' '+ word
          tags[i+1] = a
    

    【讨论】:

      【解决方案2】:

      【讨论】:

      • 这是一个模糊的句子和几个链接。答案应该回答问题:)。
      • 请用解释回答问题,并附上链接
      猜你喜欢
      • 1970-01-01
      • 2018-05-27
      • 2018-08-05
      • 2016-03-16
      • 2010-12-31
      • 2018-08-22
      • 2016-10-13
      • 1970-01-01
      • 2012-04-30
      相关资源
      最近更新 更多