Skip to content

Instantly share code, notes, and snippets.

@databrit
Last active March 22, 2019 13:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save databrit/b5407097fcb69ab7495eaa7af1e0c8b4 to your computer and use it in GitHub Desktop.
Save databrit/b5407097fcb69ab7495eaa7af1e0c8b4 to your computer and use it in GitHub Desktop.
import pandas as pd
import time
from nltk.sentiment import SentimentIntensityAnalyzer
t0 = time.time()
top_100 = pd.read_csv('/Users/brit.cava/Desktop/TabPy/top100.csv')
text = top_100['Word']
sid = SentimentIntensityAnalyzer()
word_score_dict = {}
for word in text:
ss = sid.polarity_scores(word)
word_score_dict[word]=(ss['compound'])
t1 = time.time()
total = t1-t0
print(total)
df = pd.DataFrame(list(word_score_dict.iteritems()), columns=['word','score'])
df.to_csv("/Users/brit.cava/Desktop/Scores.csv", index=False, cols=('word','score'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment