I'm trying to use YAKE to extract the keywords from a list of books' summaries.
df = {'Book': [1, 2], 'Summary': ['text definition includes the original words of something written, printed, or spoken', 'example of the Lorem ipsum placeholder text on a green and white webpage']}
df = pd.DataFrame(df)
Then I tried to use a loop and extract 1 keyword from each summary:
for i in df['Summary']:
language = "en"
max_ngram_size = 1
deduplication_threshold = 0.9
numOfKeywords = 2
custom_kw_extractor = yake.KeywordExtractor(lan=language, n=max_ngram_size, dedupLim=deduplication_threshold, top=numOfKeywords, features=None)
keywords = custom_kw_extractor.extract_keywords(i)
for kw, w in keywords:
print(kw)
Th output is:
printed
Lorem
However, I'd like to add them as a new column in the same dataframe. The final output should be:
| Book | Summary | Keywods |
|---|---|---|
| 1 | text definition includes the original words of something written, printed, or spoken | printed |
| 2 | example of the Lorem ipsum placeholder text on a green and white webpage | Lorem |
I tried to make a new list
df['keywords'] = kw
but it didn't work! It's been a while since I used Python and pandas and I don't seem to remember to do that!
Any help would be appreciated!