簡體   English   中英

'字符串'具有錯誤的類型(預期的str,得到了spacy.tokens.doc.Doc)

[英]'string' has incorrect type (expected str, got 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...

我將令牌添加到字符串中:

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

我想要的是使用Spacy將評論標記化。 這是我嘗試的方法,但是出現以下錯誤:

參數'string'具有錯誤的類型(預期的str,得到了spacy.tokens.doc.Doc)

我該如何解決? 提前致謝!

for循環中,您將從數據幀中獲取spacy.tokens並將其附加到字符串,因此應將其強制轉換為str 像這樣:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM