【发布时间】:2020-11-06 00:37:15
【问题描述】:
我发现将以下代码应用于我的数据集中的一列有一些困难:
import spacy
import pandas as pd
nlp = spacy.load('en_core_web_sm',disable=['ner','textcat'])
def f(text):
pos = ""
for token in text:
pos += token.pos_ + " "
return pos
df['Structure']= df.Low_Sentences.str.apply(f)
Low_Sentences 是这样的:
Low_Sentences
A sentence is a set of words that is complete in itself
Seeing a specific word used in a sentence can provide more context and help you better understand proper usage.
Short example: She walks.
但我收到此错误:
AttributeError: 'StringMethods' 对象没有属性 'apply'
您能告诉我如何应用该函数来获取数据框中每一行的结构吗?谢谢
【问题讨论】:
-
什么是
pos_?如果text是一个字符串,token也是一个字符串并且没有为字符串定义pos_方法 -
我正在尝试使用这个算法stackoverflow.com/questions/63763542/… 但对于每一行,不仅仅是一个字符串