【问题标题】:'string' has incorrect type (expected str, got spacy.tokens.doc.Doc)'string' 的类型不正确(预期为 str,得到 spacy.tokens.doc.Doc)
【发布时间】:2018-12-10 15:26:06
【问题描述】:

我有一个数据框:

train_review = train['review']
train_review

看起来像:

0      With all this stuff going down at the moment w...
1      \The Classic War of the Worlds\" by Timothy Hi...
2      The film starts with a manager (Nicholas Bell)...
3      It must be assumed that those who praised this...
4      Superbly trashy and wondrously unpretentious 8...

我将标记添加到字符串中:

train_review = train['review']
train_token = ''
for i in train['review']:
   train_token +=i

我想要的是使用 Spacy 对评论进行标记。 这是我尝试过的,但出现以下错误:

参数“字符串”的类型不正确(预期为 str,得到 spacy.tokens.doc.Doc)

我该如何解决?提前致谢!

【问题讨论】:

    标签: python nlp spacy


    【解决方案1】:

    for 循环中,您从数据框中获取 spacy.tokens 并将它们附加到字符串中,因此您应该将其转换为 str。 像这样:

    train_review = train['review']
    train_token = ''
    for i in train['review']:
       train_token += str(i)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-26
      • 2021-09-06
      • 1970-01-01
      • 2017-01-19
      • 1970-01-01
      相关资源
      最近更新 更多