Last active
September 3, 2020 18:14
-
-
Save josht-jpg/6b7da8b18f139aa7ff54696ee865424e to your computer and use it in GitHub Desktop.
NRC analysis
This file contains 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
NRC = pd.read_csv("NRC.csv", names=["word", "sentiment", "classifaction"]) | |
NRC_sentiments = ['anger', 'anticipation', 'disgust', 'fear', 'joy', 'negative', | |
'positive', 'sadness', 'suprise', 'trust'] | |
def nrc_classify(word): | |
return NRC[NRC['word'] == word].loc[:, 'classifaction'].tolist() | |
def nrc_clean(book_nrc): | |
book_nrc['classifications'] = book_nrc['word2'].apply(nrc_classify) | |
book_nrc = book_nrc[book_nrc['classifications'].str.len() > 0] | |
classification_df = pd.DataFrame.from_dict(dict(book_nrc['classifications'])).transpose() | |
classification_df.columns = NRC_sentiments | |
book_nrc = book_nrc.join(classification_df) | |
book_nrc = book_nrc.drop(['classifications'], axis = 1) | |
return book_nrc | |
def nrc_context(book_bigrams): | |
for e in NRC_sentiments: | |
book_bigrams[e] = book_bigrams.apply( | |
lambda x: x[e] * -1 if x['word1'] in negations else x[e], | |
axis = 1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment