Python 无法将提取的带词性标记的名词短语附加到数据框
我试图只提取名词和名词短语来处理数据(csv文件中的一列) 我能够从数据中删除停止词、标点符号和数字。还可以对数据进行POS标记,但不能提取名词短语并附加回数据框。让我知道出了什么问题Python 无法将提取的带词性标记的名词短语附加到数据框,python,pandas,nlp,Python,Pandas,Nlp,我试图只提取名词和名词短语来处理数据(csv文件中的一列) 我能够从数据中删除停止词、标点符号和数字。还可以对数据进行POS标记,但不能提取名词短语并附加回数据框。让我知道出了什么问题 stopwords=nltk.corpus.stopwords.words('english') user_defined_stop_words=['hong','kong','hk','kowloon','hongkong'] new_stop_w
stopwords=nltk.corpus.stopwords.words('english')
user_defined_stop_words=['hong','kong','hk','kowloon','hongkong']
new_stop_words=stopwords+user_defined_stop_words
data['Clean_addr'] = data['Adj_Addr'].apply(lambda x: ' '.join([item.lower() for item in x.split()]))
data['Clean_addr']=data['Clean_addr'].apply(lambda x:"".join([item.lower() for item in x if not item.isdigit()]))
data['Clean_addr']=data['Clean_addr'].apply(lambda x:"".join([item.lower() for item in x if item not in string.punctuation]))
data['Clean_addr'] = data['Clean_addr'].apply(lambda x: ' '.join([item.lower() for item in x.split() if item not in (new_stop_words)]))
texts = data['Clean_addr'].tolist()
tagged_texts = pos_tag_sents(map(word_tokenize, texts))
data['POS']=tagged_texts
data['POS']=data['POS'].apply(lambda x:' '.join([item[0] for item in x if (item[0][1]=='NNP' or item[0][1]=='NNS')]))
我正在使用的文件的示例转储
基于链接的数据:
data['POS'].apply(lambda x : ','.join([i[0] for i in x if (i[1]=='NNS' or i[1] =='NNP')]))
0 des
1 des
2 cfa,des
3 registrations
4
5 floors
6 queens
7 queens
8 queens
9
10 solicitors
11
12
13
14
15 des
Name: POS, dtype: object
从地址中提取名词有意义吗?您试图实现什么?
(项目[0][1]='NNP'或项目[0][1]=='NNS')
?它们是元组,您正在使用列表理解,所以只需执行(item[1]=='NNP'或item[1]=='NNS')
@MaxU,我正在尝试NNP@Dark,它不工作,它只是将标记(NNS,NNP)附加到数据帧。我想加上这些词你确定吗。我试过密码。它确实附加了这些词。哈哈,真的发生了。祝你好运:)也许是['NNS','NNP']中的i[1]
?