【发布时间】:2017-01-13 22:25:48
【问题描述】:
我想从数据框中提取名词。我这样做如下
import pandas as pd
import nltk
from nltk.tag import pos_tag
df = pd.DataFrame({'pos': ['noun', 'Alice', 'good', 'well', 'city']})
noun=[]
for index, row in df.iterrows():
noun.append([word for word,pos in pos_tag(row) if pos == 'NN'])
df['noun'] = noun
我得到 df['noun']
0 [noun]
1 [Alice]
2 []
3 []
4 [city]
我使用正则表达式
df['noun'].replace('[^a-zA-Z0-9]', '', regex = True)
一次又一次
0 [noun]
1 [Alice]
2 []
3 []
4 [city]
Name: noun, dtype: object
怎么了?
【问题讨论】:
标签: python nltk pos-tagger