data to CSV (for import to Tableau)

Recently I received a request to pull some metrics for our use of in social media and display them in a Tableau dashboard. While Tableau doesn’t have a native connection to there is a great example from Andy Cotgreave on how to do this here: Analysing click counts from using Python and Tableau

I gave that a shot however it requires the use of ‘bundles’ in which my social media team was not using. So what I have done is create a separate github repository with a script that will pull click counts by country and by date for an explicit list of links or using the user_popular_links() API call.

Here are the setup instructions if you’d like to just jump right in:

  1. download my code from github here:
  2. download and install python (
  3. install (
  4. rename as and edit values with your own
  5. edit pop_links array and date range inside
  6. run
  7. (optional) setup nightly job to run

I also want to mention that I chose to write this data out to a Comma Separated Values (CSV) file because the Tableau Data Extract (TDE) API does not support performing incremental updates. This means that if you wanted to port this data directly into a TDE you would need to regenerate the entire data set every time, when all you really need are the latest updates. also has a rate limit on their API which I ran into often so doing a full refresh of the TDE every day wasn’t an option. This way you just write out the most recent data to the CSV file then build your TDE off that and setup a nightly incremental update on your Tableau Server.

If you’re new to python I recommend the following tutorials to get started:


Experience The Joy of Tableau, See your Data

This Free 5-Day Video Course Contains
  • Tableau Product Family
  • User Interface and Terminology
  • Connecting to Data Sources
  • Drawing Charts
  • Sharing Your Insights