【发布时间】:2019-02-18 19:07:08
【问题描述】:
import spacy, en_core_web_sm
nlp = en_core_web_sm.load()
doc = nlp(u"I will go to the mall")
chk_set = set(['VERB'])
print chk_set.issubset(t.pos_ for t in doc)
上面的代码返回 True if POS = verb 存在。
现在我想扩展此代码以阅读存储在 Excel 表中的句子列表。为了检查句子中标点符号的存在,我可以使用下面的代码来实现它。
问题是如何扩展下面的代码以合并上面的动词检查。
from pandas import read_excel
import pandas as pd
import xlsxwriter
my_sheet_name = 'Metrics'
df = read_excel('sentence.xlsx', sheet_name = my_sheet_name)
df['.']=df['Sentence'].str.contains('.')
# df['VERB']=df['Sentence'].str.contains('.')
writer = pd.ExcelWriter('sentence.xlsx', engine='xlsxwriter')
df.to_excel(writer, sheet_name='Metrics')
writer.save()
预期结果:
Sentence Verb
I will go to the mall True
the mall False
I may be here tomorrow. True
【问题讨论】:
-
更重要的是,我想知道如何将数据帧传递给 nlp。