【发布时间】:2020-03-10 14:49:20
【问题描述】:
我已经尝试了很多方法来对我的 csv 文件中的列进行名称实体识别,我尝试了 ne_chunk 但我无法在这样的列中获得我的 ne_chunk 的结果
ID STORY PERSON NE NP NN VB GE
1 Washington, a police officer James... 1 0 0 0 0 1
改为使用此代码后,
news=pd.read_csv("news.csv")
news['tokenize'] = news.apply(lambda row: nltk.word_tokenize(row['STORY']), axis=1)
news['pos_tags'] = news.apply(lambda row: nltk.pos_tag(row['tokenize']), axis=1)
news['entityrecog']=news.apply(lambda row: nltk.ne_chunk(row['pos_tags']), axis=1)
tag_count_df = pd.DataFrame(news['entityrecognition'].map(lambda x: Counter(tag[1] for tag in x)).to_list())
news=pd.concat([news, tag_count_df], axis=1).fillna(0).drop(['entityrecognition'], axis=1)
news.to_csv("news.csv")
我收到了这个错误
IndexError : list index out of range
所以,我想知道我是否可以使用 spaCy 来做到这一点,这是我不知道的另一件事。有人可以帮忙吗?
【问题讨论】:
标签: python pandas csv nltk named-entity-recognition