/  Technology   /  Integrate python with Tableau
INTEGRATE PYTHON WITH TABLEAU (i2tutorials)

Integrate python with Tableau

Need for integration of Python with Tableau ?

Python is a high level but easy programming language that is very famous for creating machine learning models and model visualizations. Most of the time, the data scientists work with libraries like matplotlib, seaborn, etc. to build model visualizations to understand more about the model visually.

But they are not much great in styling when compared to the visualizations build in tableau. So, to give the good styling with Tableau and also Tableau’s wonderful graphical interface which can be used to modify the visualizations will be much helpful accordingly.

Tabpy Library

Tableau itself has developed TabPy and allows you to use Python scripts within the calculated columns of Tableau. After running your machine learning model, you can call functions into the calculated column.

Python Installation and Tabpy library

To implement this, you need to first install the python in your system. Once, you are done with the installation you need to install the library called “Tabpy”.

You can install Tabpy using below steps:

1. Download the Tabpy from here: https://github.com/tableau/TabPy

2. Start the Tabpy process by clicking on startup icon which windows command script ( if you are using windows)

3. Start tableau > Help > Settings and performance > Manage External Service Connections

4. Select Tabpy from the dropdown > server selection as localhost > port number 9004 ( which is default port number )

5. Creating the python script in and as a Calculated field

SCRIPT_REAL("
import numpy as np
from sklearn import linear_model
clf=linear_model.LinearRegression()
x=np.transpose(np.array([_arg1]))
y=np.array(_arg2)
clf.fit(x,y)
return clf.predict(x).tolist()",
SUM([Sales]),sum([Profit])
)

Below is the real syntax for tableau:

SCRIPT_REAL(" script " , x, y )

Leave a comment