'字符串'具有错误的类型(预期的str,得到了spacy.tokens.doc.Doc) [英] 'string' has incorrect type (expected str, got spacy.tokens.doc.Doc)
本文介绍了'字符串'具有错误的类型(预期的str,得到了spacy.tokens.doc.Doc)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据框:
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...
我将令牌添加到字符串中:
I add the tokens into a string:
train_review = train['review']
train_token = ''
for i in train['review']:
train_token +=i
我想要的是使用Spacy将评论标记化. 这是我尝试的方法,但出现以下错误:
What I want is to tokenize the reviews using Spacy. Here is what I tried, but I get the following error:
参数'string'具有错误的类型(预期的str,得到了 spacy.tokens.doc.Doc)
Argument 'string' has incorrect type (expected str, got spacy.tokens.doc.Doc)
我该如何解决?预先感谢!
How can I solve that? Thanks in advance!
推荐答案
在您的for
循环中,您将从数据帧中获取spacy.token,并将其附加到字符串中,因此应将其强制转换为str
.
像这样:
In your for
loop you are taking spacy.tokens from your dataframe and appending them to a string, so you should cast it to str
.
Like this:
train_review = train['review']
train_token = ''
for i in train['review']:
train_token += str(i)
这篇关于'字符串'具有错误的类型(预期的str,得到了spacy.tokens.doc.Doc)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文