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