-
-
Save radovankavicky/969d664f4645b342e40614c5f8ac41fb to your computer and use it in GitHub Desktop.
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
#SCRIPT_REAL is a function in Tableau which returns a result from an external service script. It's in this function we pass the python code. | |
SCRIPT_REAL("from nltk.sentiment import SentimentIntensityAnalyzer | |
text = _arg1 #you have to use _arg1 to reference the data column you're analyzing, in this case [Word]. It gets word further down after the , | |
scores = [] #this is a python list where the scores will get stored | |
sid = SentimentIntensityAnalyzer() #this is a class from the nltk (Natural Language Toolkit) library. We'll pass our words through this to return the score | |
for word in text: # this loops through each row in the column you pass via _arg1; in this case [Word] | |
ss = sid.polarity_scores(word) #passes the word through the sentiment analyzer to get the score | |
scores.append(ss['compound']) #appends the score to the list of scores | |
return scores #returns the scores | |
" | |
,ATTR([Word])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment