title: How to Apply pos_tag to All Words in a Column in Pandas Dataframe
body: <p>I am trying to apply PoS tagging to a column in a PD dataframe which includes multiple words in each row.</p>
  <pre><code>data = {
    &quot;col1&quot;: ['apartments expectations better','amazing amazingly resolver better', 'been says amazingly', 'places was','airports really beautiful!', 'stopped you']
  }
  
  df = pd.DataFrame(data)
  </code></pre>
  <p>The current codes only allow me to apply PoS to first words in each row only.</p>
  <pre><code>from nltk.corpus import wordnet as wn
  from nltk.tag import pos_tag
  from nltk.stem import WordNetLemmatizer
  from nltk.corpus import wordnet as wn
  from nltk.tag import pos_tag
  from nltk.stem import WordNetLemmatizer
  from nltk.tokenize import word_tokenize
  nltk.download('punkt')
  nltk.download('averaged_perceptron_tagger')
  
  def lemmatize_all(sentence):
      wnl = WordNetLemmatizer()
      for word, tag in pos_tag(word_tokenize(sentence)):
          #if tag.startswith(&quot;NN&quot;):
          if tag.startswith(&quot;N&quot;):
              return wnl.lemmatize(word, pos='n')
          #elif tag.startswith('VB'):
          elif tag.startswith('V'):
              return wnl.lemmatize(word, pos='v')
          #elif tag.startswith('JJ'):
          elif tag.startswith('J'):
              return wnl.lemmatize(word, pos='a')
          elif tag.startswith('R'):
              return wnl.lemmatize(word, pos='r')    
          else:
              return word
  
  df['col1']=df['col1'].apply(str).map(lemmatize_all)
  print (df)
  </code></pre>
  <pre><code>Current Outputs:
   col1
  0  apartment
  1      amaze
  2         be
  3      place
  4    airport
  5       stop
  </code></pre>
  <p>But I want to apply it to all the rest of the words in every row.
  Any help would be appreciated.</p>