【发布时间】:2019-10-08 15:18:30
【问题描述】:
我正在从文本中提取诸如名词计数之类的文本特征。以下功能消耗太多时间。我该如何优化它?
import spacy
nlp = spacy.load('en')
def get_numeric_features(df):
df['NOUN_COUNT'] = df.apply(lambda x: len([token.pos_ for token in nlp(x['TITLE_TEXT']) if token.pos_ == 'NOUN']),axis=1)
return df
start = time.time()
df1 = get_numeric_features(df1)
end = time.time()
print(end - start)
df1.head()
花费的时间(130000 行大约需要 23 分钟)
1415.4789326190948
【问题讨论】:
标签: python-3.x feature-extraction spacy natural-language-processing