0
我想从数据框中提取名词。我做如下如何删除结果中的方括号pos_tag
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 [ '名词']
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
有什么不对?
如果什么有多个元素? – Enthusiast