Last active
July 30, 2019 05:46
-
-
Save emmagrimaldi/927fae042b1ccc48ba8613857ca2ebdd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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