Integrating Python with Tableau – A Quick Guide

Blog | June 2, 2023 | By Gajender Kumar

The Power of Integration: Combining Python and Tableau for Enhanced Data Analysis

In the current digital age, data analysis and visualization are essential for businesses. But how can one combine the best of both worlds: the flexibility and versatility of Python, a powerful programming language, and the simplicity and elegance of Tableau, one of the world’s leading data visualization tools? The answer is Integration!

Introduction to Python and Tableau Integration

Unlocking Advanced Analytical Capabilities with Python and Visualizations with Tableau

By integrating Python with Tableau, one can leverage the advanced analytical capabilities of Python and the stunning visualizations of Tableau to create compelling and insightful reports and dashboards. In this blog, we will show you how to integrate Python with Tableau in a few easy steps.

Step-by-Step Guide: Integrating Python with Tableau

Step 1: Install Python

Before integrating Python with Tableau, you need to ensure that Python is installed on your computer. You can download and install the latest version of Python from the official website.

Step 2: Install TabPy

TabPy is a Python package that allows you to execute Python scripts from Tableau. To install TabPy, follow these steps:

  1. Open the command prompt or terminal window on your computer.
  2. Type “pip install tabpy” and press enter.
  3. Wait for the installation to complete.

Step 3: Configure TabPy

After installing TabPy, you need to configure it to work with Tableau. Follow these steps to configure TabPy:

  1. Open the command prompt or terminal window.
  2. Type “tabpy” and press enter to start the TabPy server.
  3. Open Tableau and go to “Help” > “Settings and Performance” > “Manage External Service Connection”.
  4. In the “TabPy” section, enter the server name and port number (default is 9004).
  5. Click “Test Connection” to verify that the connection is successful.
  6. Click “Apply” and “OK” to save the settings.

Step 4: Create a Python Script

Now that TabPy is configured, you can create a Python script that can be executed from Tableau. Here is an example Python script that returns the sum of two numbers:

pythonCopy code

def sum(a, b): return a + b

Save this script as “sum.py” in a directory of your choice.

Step 5: Publish the Python script to TabPy

To execute the Python script from Tableau, you need to publish the script to TabPy. Follow these steps to publish the script:

  1. Open the command prompt or terminal window.
  2. Type “tabpy-deploy” and press enter.
  3. In the “Model Repository Path” field, enter the directory where the “sum.py” script is saved.
  4. Click “Deploy New” to publish the script to TabPy.

Step 6: Connect Tableau to TabPy

After publishing the script to TabPy, you can connect Tableau to TabPy and execute the script. Follow these steps to connect Tableau to TabPy:

  1. Open Tableau and create a new worksheet.
  2. Drag and drop a dimension and a measure to the view.
  3. Click “Analysis” > “Create Calculated Field”.
  4. In the “Functions” section, select “Script” and click “Create”.
  5. In the “Script” section, select “TabPy” as the language.
  6. In the “Function Name” field, enter “sum”.
  7. In the “Script” field, enter “sum([Number 1], [Number 2])” and click “OK”.
  8. The calculated field will return the sum of the two numbers.

Elevate Your Tableau Dashboards with Python Integration

Maximizing Data Analysis and Visualization with Python and Tableau

Integration of Python with Tableau offers a precious opportunity for data professional to elevate the visualization and analytical prowess of the Tableau. By following the steps and substeps in this brief guide, users can seamlessly integrate Python into their Tableau workflow, harnessing the power of Python to augment the depth and breadth of their Tableau dashboards.

gajender-kumar
About the Author
Gajender Kumar is an experienced analytics professional with a passion for transforming data into business insights. With his expertise in data warehousing and data visualization and a hands-on approach to creating impactful Tableau/Power BI dashboards, Kumar knows how to make data work for you.
Gajender KumarLead BI Analyst | USEReady