This exercise is based on the idea of Brit Cava, who used the Makeover Monday data from the top 100 song lyrics in order to try out the Tableau-Python integration. You can find the blog post here: https://www.tableau.com/about/blog/2016/12/using-python-sentiment-analysis-tableau-63606. Let's reproduce it with another dataset:
- Navigate to the Sentiment tab in the workbook associated with the chapter.
- Connect to the Lord of the Rings data source.
- Connect Tableau to Python.
- Create a Sentiment Scores calculated field:
SCRIPT_REAL("from nltk.sentiment import SentimentIntensityAnalyzertext = _arg1scores = []sid = SentimentIntensityAnalyzer()for word in text: ss = sid.polarity_scores(word) scores.append(ss['compound']) ...