Skip to content Skip to sidebar Skip to footer

Applying Synsets To Pandas

This seems like such a simple question but I'd like to avoid looping if possible. I have the following data set in a panda column: df['token']: 0 [If, you, can, only, visit, on

Solution 1:

From your comments, I think what you are looking for is a way to replace each of the words with the first result from calling synsets on the word, Is that correct? You just need a function that wraps synsets that accepts a list of words, and returns the first element of what synset returns for each one of those:

deffirst(wordlist):
    # wordlistisalistofwords, i.e. ['sun', 'shine', 'spotless']return[synsets(word)[0]forwordinwordlist]

Then use applymap to run it on each element of the DataFrame:

df.applymap(first)

Is that what you're trying to do?

Post a Comment for "Applying Synsets To Pandas"