【发布时间】:2019-02-04 16:25:28
【问题描述】:
我正在尝试将 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)
如何在我的数据框列上实现函数以返回正确的函数输出?
【问题讨论】:
-
你没有从你定义的函数中返回任何东西。您需要添加一个 return 语句以使用 apply 将分配返回到您的列。
标签: python pandas nlp spacy textacy