Skip to content

Instantly share code, notes, and snippets.

@josht-jpg
Last active September 2, 2020 19:31
Show Gist options
  • Save josht-jpg/1a6f3f94bf152f8d6ee5c77e822c7524 to your computer and use it in GitHub Desktop.
Save josht-jpg/1a6f3f94bf152f8d6ee5c77e822c7524 to your computer and use it in GitHub Desktop.
beginning with AFINN
from afinn import Afinn
afinn = Afinn()
def afinn_context(book_bigrams):
book_bigrams['score'] = book_bigrams['word2'].apply(afinn.score)
book_bigrams['score'] = book_bigrams.apply(
lambda x: x['score'] * -1 if x['word1'] in negations else x['score'],
axis = 1)
return book_bigrams
notes_afinn = afinn_context(notes_bigrams)
crime_afinn = afinn_context(crime_bigrams)
idiot_afinn = afinn_context(idiot_bigrams)
possessed_afinn = afinn_context(possessed_bigrams)
brothers_afinn = afinn_context(brothers_bigrams)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment