【问题标题】:POS Tagging in Dataframe pandas-TextblogDataframe pandas-Textblog 中的 POS 标记
【发布时间】:2018-03-28 04:16:35
【问题描述】:

我正在尝试对数据框中存在的文本执行 POS 标记。我尝试使用 TextBlob,但没有得到想要的结果。我想要的结果是“应该使用所有标记创建一个新列”。 例如:“我喜欢 stackoverflow”,我的新列 POS_tagged 应该有 [('I', 'PRP'), ('like', 'VBP'), ('stackoverflow', 'JJ')]

我尝试使用 Textblob,但它只适用于一个句子。它不适用于一系列句子。

def postag(sentence1):
blob=TextBlob(sentence1)
return blob.tags

aspect_new["POS"]=aspect_new['tweets'].apply(postag)

我遇到了错误

TypeError: The `text` argument passed to `__init__(text)` must be a string, not <class 'float'>

您能帮我在 textblob 中实现同样的目标吗?

【问题讨论】:

    标签: python text-mining textblob


    【解决方案1】:

    问题可以通过以下方式解决

    from nltk import word_tokenize, pos_tag, pos_tag_sents
    tweet=aspect_new['tweets'].tolist()
    tw=[]
    for i in tweet:
       tw.append(str(i))
    
    tagged_texts = pos_tag_sents(map(word_tokenize, tw))
    aspect_new["POS tags"]=tagged_texts
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-30
      • 2016-07-02
      • 1970-01-01
      • 2012-06-14
      相关资源
      最近更新 更多