簡體   English   中英

從熊貓數據框中的列中刪除自定義停用詞列表

[英]Removing a custom stop words list from a column in a pandas data frame

我正在分析一長串調查回復。 我可以很好地刪除標准 nltk 列表中的停用詞。 但是,我創建了一個修改后的列表,似乎無法將其合並到代碼中。 我用於標准列表的原始代碼是:

#creating 一列,其中停用詞從一列中刪除,我已從響應中刪除標點符號,這些響應也已被標記並全部小寫。

stop_words = set(stopwords.words('english'))

df['stopwords_removed'] = df['no_punc'].apply(lambda x: [word for word in x if word not in stop_words])

df.head()

我已使用以下代碼添加到標准列表中:

stop_words = set(stopwords.words('english'))

new_stopwords = ['satisfying', 'satisfy', 'satisfied', 'clemson', 'university', 'institution', 'disappointing', 'disappoint', 'disappointed', 'experience', 'would', 'should']

new_stopwords_list = stop_words.union(new_stopwords)

我的問題是如何修改我的原始代碼以包含 new_stopwords_list 而不是標准代碼?

我不確定我是否完全理解,但為什么你不能使用同一行代碼然后檢查新集合中的成員資格? 所以:

df['stopwords_removed'] = df['no_punc'].apply(lambda x: [word for word in x if word not in new_stopwords])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM