我正在尝试将textacy.extract.subject_verb_object_triples函数应用于pandas df列。该函数按如下方式应用时返回空生成器对象,而不是subject_verb_object_triples:
sp500news3['title'].apply(lambda x: textacy.extract.subject_verb_object_triples)或
sp500news3['title'].apply(textacy.extract.subject_verb_object_triples)我也尝试过:
import spacy
import textacy
def extract_SVO1(text):
new_doc = textacy.extract.subject_verb_object_triples(text)
new_list = list(new_doc)
text = new_list
sp500news3['title'] = sp500news3['title'].apply(extract_SVO1)如何在我的dataframe列上实现函数以返回正确的函数输出?
发布于 2019-02-05 20:41:04
原因是textacy.extract.subject_verb_object_triples返回一个生成器,该生成器必须转换为某种可迭代类型。您的两种方法都是可行的,但需要进行一些修改。
第一种方法:使用生成器
sp500news3['title'].apply(lambda x: textacy.extract.subject_verb_object_triples).apply(pd.Series)
第二种方法:编写一个单独的函数来应用
def extract_SVO1(text):
new_doc = textacy.extract.subject_verb_object_triples(text)
new_list = list(new_doc)
return new_listhttps://stackoverflow.com/questions/54520316
复制相似问题