简体   繁体   中英

TypeError: Argument 'string' has incorrect type (expected str, got float)

I am working on a code for aspect extraction. I was getting the following error. can anyone help me resolve this?

aspect_terms = [] for review in nlp.pipe(df2.review): chunks = [(chunk.root.text) for chunk in review.noun_chunks if chunk.root.pos_ == 'NOUN'] aspect_terms.append(''.join(chunks))

TypeError: Argument 'string' has incorrect type (expected str, got float).

Covert chunk.root.text to a string during list comprehension. .join requires strings in the iterable.

aspect_terms = [] 
for review in nlp.pipe(df2.review):
    chunks = [str(chunk.root.text) for chunk in review.noun_chunks if chunk.root.pos_ == 'NOUN']
    aspect_terms.append(''.join(chunks))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM