title: how to remove punctuation and stop words using python
body: <p>I have a python function that must remove <strong>punctuation</strong> and <strong>stop words</strong> but when i print the result it does't remove it.</p>
  <p>where is the error in my function?</p>
  <p>code:</p>
  <pre><code>    from nltk.corpus import stopwords
      from string import punctuation
          ppt = '''...!@#$%^&amp;*(){}[]|._-`/?:;&quot;'\,~12345678876543''' 
      
          def text_process(raw_text):
              '''
              parameters:
              =========
              raw_text: text as input
              functions:
              ==========
              - remove all punctuation
              - remove all stop words
              - return a list of the cleaned text
          
              '''
              #check characters to see if they are in punctuation
              nopunc = [char for char in list(raw_text)if char not in ppt]
            
              # join the characters again to form the string
              nopunc = &quot;&quot;.join(nopunc)
              
              #now just remove ant stopwords
              return [word for word in nopunc.lower().split() if word.lower() not in stopwords.words(&quot;english&quot;)]
  
  def_test_twtr_preds[&quot;tokens&quot;] = def_test_twtr_preds[&quot;processed_TEXT&quot;].apply(text_process)
  
  
  #get most common words in  dataset
  all_words = []
  for line in list(def_test_twtr_preds[&quot;processed_TEXT&quot;]):
      words = line.split()
      for word in words:
          all_words.append(word.lower())
  print(&quot;Most common words:\n{}&quot;.format(Counter(all_words).most_common(10)))
  </code></pre>
  <p>when i display the result of most common words exist in the dataset is:</p>
  <pre><code>Most common words:
  [('the', 281), ('and', 103), ('words', 81), ('…', 70), ('are', 61), ('word', 57), ('for', 55), ('you', 48), ('this', 40), ('.', 34)]
  </code></pre>