Skip to content

Instantly share code, notes, and snippets.

@emmagrimaldi
Last active July 30, 2019 05:46
Show Gist options
  • Select an option

  • Save emmagrimaldi/927fae042b1ccc48ba8613857ca2ebdd to your computer and use it in GitHub Desktop.

Select an option

Save emmagrimaldi/927fae042b1ccc48ba8613857ca2ebdd to your computer and use it in GitHub Desktop.
# initializing the new column
df['Key_words'] = ""
for index, row in df.iterrows():
plot = row['Plot']
# instantiating Rake, by default it uses english stopwords from NLTK
# and discards all puntuation characters as well
r = Rake()
# extracting the words by passing the text
r.extract_keywords_from_text(plot)
# getting the dictionary whith key words as keys and their scores as values
key_words_dict_scores = r.get_word_degrees()
# assigning the key words to the new column for the corresponding movie
row['Key_words'] = list(key_words_dict_scores.keys())
# dropping the Plot column
df.drop(columns = ['Plot'], inplace = True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment