Usually, I really don’t like looking on the screens of other passengers. On this early morning train from Frankfurt to Cologne, however, the screen of my seatmate caught my attention. Where have I seen the logo on his slide deck before? Two coffee sips later, it came to me: it was the logo of Monkey 47, a very delicious gin, distilled in the heart of the Black Forest. So I asked my neighbor: “Is that the Monkey 47 logo?”
He was happy that I recognized his brand and we had a small chat about gin and the Black Forest. Turns out his name is Thomas, and he is the head of Sales and Marketing for Monkey 47. Thomas mentioned that his team is planning a tour to promote Monkey 47 in a number of cities. That sounds similar to what we are doing with the Tableau Cinema Tour, so I showed him our Cinema Tour landing page and explained briefly who we are and what our mission is.
I asked him how he is organizing his data. Thomas revealed that he lives in Excel hell: “spreadsheets with thousands of rows and way too many columns”. This also sounded familiar. I opened up our Superstore.xlsx in Excel and asked: “Do your Excel sheets look like this?” Thomas replied: “Yes!”
Here we go! I drag’n’dropped the file on my Tableau desktop icon and paced through a 7-minute-demo ending with an interactive dashboard. Thomas was flabbergasted. To polish things off, I showed him the interactive Twitter Sentiment Dashboard embedded in my blog. Thomas grabbed his jacket and gave me a business card, saying: “We need Tableau!”
This story was originally written for Tableau’s EMEA Sales Newsletter. I think it’s a good read for the holidays, and wish you all Merry Christmas!
In 2013, Tableau introduced R Integration, the ability to call R scripts in calculated fields. This opened up possibilities such as K-means clustering, Random Forest models, and sentiment analysis. With the release of Tableau 10.2, we can enjoy a new, fancy addition to this feature: the Python Integration through TabPy, the Tableau Python Server.
Python in Tableau: The Perfect Blend
Python is a widely used general-purpose programming language, popular among academia and industry alike. It provides a wide variety of statistical and machine-learning techniques and is highly extensible. Together, Python and Tableau are the data science dream team to cover any organization’s data analysis needs.
In this tutorial, I’m going to walk you through the installation and connecting Tableau with TabPy. I will also give you an example of calling a Python function from Tableau to calculate correlation coefficients for a trellis chart.
Step by Step: Integrating Python in Tableau
1. Install and start Python and TabPy
Start by clicking on the Clone or download button in the upper right corner of the TabPy repository page, downloading the zip file, and extracting it.
Protip: If you are familiar with Git, you can download TabPy directly from the repository:
> git clone git://github.com/tableau/TabPy
Within the TabPy directory, execute setup.sh (or setup.bat if you are on Windows). This script downloads and installs Python, TabPy, and all necessary dependencies. After completion, TabPy is starting up and listens on port 9004.
2. Connecting Tableau to TabPy
In Tableau 10.2 (and later versions), a connection to TabPy can be added in Help > Settings and Performance > Manage External Service Connection:
Set port to 9004:
3. Adding Python code to a Calculated Field
You can invoke Calculated Field functions called SCRIPT_STR, SCRIPT_REAL, SCRIPT_BOOL, and SCRIPT_INT to embed your Python script in Tableau:
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
Now you can use your Python calculation as Calculated Field in your Tableau worksheet:
Feel free to download the Tableau Packaged Workbook (twbx) here.
Further Reading: Visual Analytics with Tableau
Join the data science conversation and follow me on Twitter and LinkedIn for more tips, tricks, and tutorials on Python in Tableau and other data analytics topics. If you’re looking to master Tableau, don’t forget to preorder your copy of my upcoming book, Visual Analytics with Tableau (Amazon). It offers an in-depth exploration of data visualization techniques and best practices.
Ist der Einsatz sozialer Netze in Ihrem Unternehmen auf Marketing beschränkt, und lässt dadurch Chancen ungenutzt?
Noch immer schöpfen viele Unternehmen in Deutschland die Möglichkeiten von Social Media nur unzureichend aus. Die meisten Firmen nutzen Social Media lediglich als Marketinginstrument, senden zum Beispiel in Intervallen die gleichen Inhalte. Wesentlich weniger Unternehmen setzen Social Media dagegen in der externen Kommunikation, in Forschung und Entwicklung, zu Vertriebszwecken, oder im Kundenservice ein.
Nachfolgend betrachten wir die Twitter-Kommunikation von vier Social-Media-affinen Unternehmen etwas näher, und zeigen anhand sieben Fragestellungen was sie anders machen und wo die übrigen Nachholbedarf haben.
1. Wann und wie werden Tweets gesendet?
Ein Blick auf das Histogram lässt auf reichlich Interaktion schließen (Tweets und Replies), während das Weiterverbreiten von Tweets (Retweets) eher sporadisch auftritt:
2. Wie umfangreich sind die Tweets?
Wie es scheint, reitzen die meisten Tweets die von Twitter vorgesehenen 140 Zeichen aus – oder sind zumindest nahe dran:
3. An welchen Wochentagen wird getweetet?
Am Wochenende lässt die Kommunikation via Twitter nach. Die Verteilung der Emotionen bleibt dabei gleich, unterscheidet sich aber von Unternehmen zu Unternehmen:
4. Zu welcher Tageszeit wird getweetet?
Auch nachts werden weniger Tweets verfasst. Bei Lufthansa kommt es dabei recht früh zu einem Anstieg durch Pendler-Tweets, etwas später tritt dieser Effekt bei der Deutschen Bahn ein:
5. Welche Art der Kommunikation herrscht vor?
Der hohe Anteil an Replies bei Telekom, Deutsche Bahn und Lufthansa impliziert, dass diese Unternehmen Twitter stark zum Dialog nutzen. Unter den Tweets der Deutsche Bank ist hingegen der Anteil an Retweets – insbesondere bei jenen mit Hashtag – deutlich höher, was auf einen höheren Nachrichtengehalt schließen lässt:
6. Welche User sind besonders aktiv?
Nun betrachten wir die Twitter-User, welche die entsprechend Twitter-Handles der Unternehmen besonders intensiv nutzen:
Je nach Emotion und Kontext ist es vor allem für das adressierte Unternehmen von Interesse rechtzeitig und angemessen zu reagieren. So lässt sich eine negative Stimmung frühzeitig relativieren, und so Schaden an der Marke abwenden. Positive Nachrichten können hingegen durch Weiterreichen als Multiplikator dienen.
Today I’d like to follow up on this and show how to implement sentiment analysis in Tableau using Tableau’s R integration. Some of the many uses of social media analytics is sentiment analysis where we evaluate whether posts on a specific issue are positive, neutral, or negative (polarity), and which emotion in predominant.
What do customers like or dislike about your products? How do people perceive your brand compared to last year?
The sentiment package requires the tm and Rstem packages, so make sure that they are installed properly. Execute these commands in your R console to install sentiment from GitHub (see alternative way to install at the end of this blog post):
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
The sentiment package offers two functions, which can be easily called from calculated fields in Tableau:
The function get_polarity returns „positive“, „neutral“, or „negative“:
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
The function get_emotion returns „anger“, „disgust“, „fear“, „joy“, „sadness“, „surprise“, or „NA“:
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
The sentiment package follows a lexicon based approach and comes with two files emotions_english.csv.gz (source and structure) and subjectivity_english.csv.gz (source and structure). Both files contain word lists in English and are stored in the R package library under /sentiment/data directory.
If text is incorrectly classified, you could easily fix this issue by extending these two files. If your aim is to analyze text other than English, you need to create word lists for the target language. Kindly share them in the comments!
Feel free to download the Packaged Workbook (twbx) here.
Update 11 Aug 2016: If you are having trouble with install_github, try to install directly form this website:
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
Tableau is an incredibly versatile tool, commonly known for its ability to create stunning visualizations. But did you know that with Tableau, you can also perform real-time, interactive text mining? Let’s delve into how we can harness this function to gain rapid insights from our textual data.
Previously, during text mining tasks, you might have found yourself reaching for a scripting language like R, Python, or Ruby, only to feed the results back into Tableau for visualization. This approach has Tableau serving merely as a communications tool to represent insights.
However, wouldn’t it be more convenient and efficient to perform text mining and further analysis directly in Tableau?
While Tableau has some relatively basic text processing functions that can be used for calculated fields, these often fall short when it comes to performing tasks like sentiment analysis, where text needs to be split into tokens. Even Tableau’s beloved R integration does not lend a hand in these scenarios.
The Power of Postgres for Text Mining in Tableau
Faced with these challenges, I decided to harness the power of Postgres‘ built-in string functions for text mining tasks. These functions perform much faster than most scripting languages. For example, I used the function regexp_split_to_table for word count, which takes a piece of text (like a blog post), splits it by a pattern, and returns the tokens as rows:
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
Incorporating Custom SQL into Tableau Visualization
I joined this code snippet as a Custom SQL Query to my Tableau data source, which is connected to the database that is powering my blog:
And here we go, I was able to create an interactive word count visualization right in Tableau:
This example can be easily enhanced with data from Google Analytics, or adapted to analyze user comments, survey results, or social media feeds. The possibilities for Custom SQL in Tableau are vast and versatile. Do you have some more fancy ideas for real-time text mining with Tableau? Leave me a comment!
Update (TC Pro Tip): Identifying Twitter Hashtags in Tableau
A simple calculated field in Tableau can help identify words within tweets as hashtags or user references, eliminating the need for another regular expression via a Custom SQL Query:
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
Any more feedback, ideas, or questions? I hope this post provides you with valuable insights into how to master text mining in Tableau, and I look forward to hearing about your experiences and creative applications. You can find more tutorials like this in my new book Visual Analytics with Tableau (Amazon).
Transparency: This blog contains affiliate links. If you click on them, you will be redirected to the merchant. If you decide to make a purchase, we will receive a small commission. The price does not change for you. Affiliate links have no influence on our writing.
Manage Cookie Consent
We use cookies to optimize our website and our service.
Functional
Immer aktiv
The technical storage or access is strictly necessary for the legitimate purpose of enabling the use of a specific service explicitly requested by the subscriber or user, or for the sole purpose of carrying out the transmission of a communication over an electronic communications network.
Preferences
The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user.
Statistics
The technical storage or access that is used exclusively for statistical purposes.The technical storage or access that is used exclusively for anonymous statistical purposes. Without a subpoena, voluntary compliance on the part of your Internet Service Provider, or additional records from a third party, information stored or retrieved for this purpose alone cannot usually be used to identify you.
Marketing
The technical storage or access is required to create user profiles to send advertising, or to track the user on a website or across several websites for similar marketing purposes.