Click here to Skip to main content
15,883,770 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have made a list of stopwords, called "stopwordlist" in Python, and then, the following code:
Python
STOPWORDS = set(stopwordlist)
def cleaning_stopwords(text):
    return " ".join([word for word in str(text).split() if word not in STOPWORDS])
data_set['text'] = data_set['text'].apply(lambda text: cleaning_stopwords(text))
data_set['text'].head()
It works well with English stopwords. However, when I try to remove Spanish or French stopwords (each language has a separate Jupyter Notebook with a different dataset, 3 in total) it doesn't remove any word. Any heads up about this?

Thanks in advance, any help will be greatly appreciated.

What I have tried:

Python
STOPWORDS = set(stopwordlist)
def cleaning_stopwords(text):
    return " ".join([word for word in str(text).split() if word not in STOPWORDS])
data_set['text'] = data_set['text'].apply(lambda text: cleaning_stopwords(text))
data_set['text'].head()
Posted
Updated 9-Jan-23 18:16pm
v3
Comments
Richard MacCutchan 9-Jan-23 12:39pm    
You need to show the actual data that your code fails on. No one here can guess what words you are using.
ltxar 9-Jan-23 13:12pm    
Sure, this is the list of Spanish stopwords I made. English and French versions are translations of these same words:

#list of the main Spanish stopwords that we'll remove from tweets

stopwordlist = ['a', 'abajo', 'acerca', 'acá', 'ahora', 'algún', 'alguna', 'allá', 'allí', 'ambos',
'ante', 'antes', 'arriba', 'así', 'aquél', 'aquella', 'aquellos', 'aquellas', 'aquí',
'bajo', 'cabe', 'cada', 'cerca', 'como', 'cómo', 'con', 'contra', 'cual', 'cualquier',
'de', 'debajo', 'delante', 'dentro', 'desde', 'después', 'detrás', 'donde', 'durante',
'el', 'él', 'ella', 'ellas', 'ellos', 'en', 'entonces', 'entre', 'era', 'eramos',
'eran', 'estando', 'es', 'esos', 'esto', 'estos', 'esta',
'fuera', 'ha', 'había', 'habido','hacia',
'hasta', 'hay', 'he', 'hubo', 'la', 'mas', 'más', 'me', 'mediante', 'mientras',
'misma', 'mucho', 'muy', 'nuestro', 'nuestra', 'no', 'nosotros', 'o', 'otra',
'otro', 'para', 'poco', 'poca','pocas', 'pocos', 'por', 'porque', 'porqués', 'propio',
'que', 'qué', 'quien', 'quién', 'según', 'si', 'siendo', 'sin', 'so', 'sobre', 'solo',
'son', 'soy', 'su', 'sus', 'tal', 'también', 'todo', 'todos', 'tras', 'través', 'tu',
'un', 'una', 'usted', 'ustedes', 'versus', 'vía', 'vosotros', 'y', 'yo']

This answer doesn't let me show indentation of the list inside the block, so that the left margin falls under the "=" sign

1 solution

You can remove stopwords from Twitter data in Python using the NLTK library. The NLTK library has a list of stopwords that you can use to filter out words from your data. To remove stopwords, you can use the NLTK's stopwords corpus to filter out the stopwords from your data.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900