Lemmatise DataFrame Text Using NLTK

Python

 1|  import nltk
 2|  nltk.download('wordnet')
 3|  from nltk.stem import WordNetLemmatizer
 4|  lemmatizer = WordNetLemmatizer()
 5|  def lemmatize_words(text):
 6|      words = text.split()
 7|      words = [lemmatizer.lemmatize(word,pos='v') for word in words]
 8|      return ' '.join(words)
 9|  df['text'] = df['text'].apply(lemmatize_words)
Did you find this snippet useful?

Sign up for free to to add this to your code library