title: removing words from a list from pandas column - python 2.7
body: <p>I have a text file which contains some strings that I want to remove from my data frame. The data frame observations contains those texts which are present in the ext file.</p>
  
  <p>here is the text file - <a href="https://drive.google.com/open?id=1GApPKvA82tx4CDtlOTqe99zKXS3AHiuD" rel="nofollow noreferrer">https://drive.google.com/open?id=1GApPKvA82tx4CDtlOTqe99zKXS3AHiuD</a></p>
  
  <p>here is the link; Data = <a href="https://drive.google.com/open?id=1HJbWTUMfiBV54EEtgSXTcsQLzQT1rFgz" rel="nofollow noreferrer">https://drive.google.com/open?id=1HJbWTUMfiBV54EEtgSXTcsQLzQT1rFgz</a></p>
  
  <p>I am using the following code - </p>
  
  <pre><code>import nltk
  from nltk.tokenize import word_tokenize 
  file = open("D://Users/Shivam/Desktop/rahulB/fliter.txt")
  result = file.read()
  words = word_tokenize(result)
  </code></pre>
  
  <p>I loaded the text files and converted them into words/tokens.</p>
  
  <p>Its is my dataframe.</p>
  
  <pre><code>text
  0   What Fresh Hell Is This? January 31, 2018 ...A...
  1   What Fresh Hell Is This? February 27, 2018 My ...
  2   What Fresh Hell Is This? March 31, 2018 Trump ...
  3   What Fresh Hell Is This? April 29, 2018 Michel...
  4   Join Email List Contribute Join AMERICAblog Ac...
  </code></pre>
  
  <p>If you see this, these texts are present in the all rows such as "What Fresh Hell Is This?" or "Join Email List Contribute Join AMERICAblog Ac, "Sign in Daily Roundup MS Legislature Elected O" etc.</p>
  
  <p>I used this for loop</p>
  
  <pre><code>for word in words:
      df['text'].replace(word, ' ')
  </code></pre>
  
  <p>my error.</p>
  
  <pre><code>error                                     Traceback (most recent call last)
  &lt;ipython-input-168-6e0b8109b76a&gt; in &lt;module&gt;()
  ----&gt; 1 df['text'] = df['text'].str.replace("|".join(words), " ")
  
  D:\Users\Shivam\Anaconda2\lib\site-packages\pandas\core\strings.pyc in replace(self, pat, repl, n, case, flags)
     1577     def replace(self, pat, repl, n=-1, case=None, flags=0):
     1578         result = str_replace(self._data, pat, repl, n=n, case=case,
  -&gt; 1579                              flags=flags)
     1580         return self._wrap_result(result)
     1581 
  
  D:\Users\Shivam\Anaconda2\lib\site-packages\pandas\core\strings.pyc in str_replace(arr, pat, repl, n, case, flags)
      422     if use_re:
      423         n = n if n &gt;= 0 else 0
  --&gt; 424         regex = re.compile(pat, flags=flags)
      425         f = lambda x: regex.sub(repl=repl, string=x, count=n)
      426     else:
  
  D:\Users\Shivam\Anaconda2\lib\re.pyc in compile(pattern, flags)
      192 def compile(pattern, flags=0):
      193     "Compile a regular expression pattern, returning a pattern object."
  --&gt; 194     return _compile(pattern, flags)
      195 
      196 def purge():
  
  D:\Users\Shivam\Anaconda2\lib\re.pyc in _compile(*key)
      249         p = sre_compile.compile(pattern, flags)
      250     except error, v:
  --&gt; 251         raise error, v # invalid expression
      252     if not bypass_cache:
      253         if len(_cache) &gt;= _MAXCACHE:
  
  error: nothing to repeat
  </code></pre>