[英]Stopwords on a DataFrame Column
我正在清理一個 excel 文件,以便可以在 PowerBi 上展示它。 我想消除特定列的停用詞,這是我正在使用的代碼,但它似乎有問題。 我需要消除的停用詞是西班牙語。
另外我正在更換 . 和 , 用於拆分列並分析信息的空間,如果您知道更簡單的方法,請告訴我。
import nlkt
from nltk.corpus import stopwords
stop = stopwords.words('spanish')
df['Producto'] = df['Producto'].apply(lambda x: ' '.join([word for word in x.split() if word not in (stop)]))
df["Producto"] = df["Producto"].str.replace(",","")
df["Producto"] = df["Producto"].str.replace(".","")
df = df["Producto"].str.split(" ", expand = True)
print (df)
這是一個快速的方法。 我用一些示例數據重新創建了一個數據框:
import re
import nltk
from nltk.corpus import stopwords
pattern = re.compile(r'\b(' + r'|'.join(stopwords.words('spanish')) + r')\b\s*')
df_temp = pd.DataFrame({'Words': ["Uno", "Dos", "Tres", "Other", "los"]})
df_temp['Words'] = df_temp['Words'].map(lambda x: pattern.sub('', str(x)))
df_temp 的輸出:
Words
0 Uno
1 Dos
2 Tres
3 Other
4
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.