Including a script of code to Tableau Prep

Including a script of code to Tableau Prep ( example with a python script, written in Jupyter Notebook)

Lately I was confronted with a data preparation task to do in Tableau Prep, where I had to fill in cells, which had nulls in them with values from a cell above. As Tableau Prep hasn’t a formula tool yet ( and the lookup function can be just used in Tableau ), there had to be another way, and there is: Tableau Prep actually gives you the possibility, to insert scripts, which contain a snippet of code, that solves the problem.

This is a brief explanation, how to insert a script (explained for a python script) in Tableau Prep.

When you click on the plus behind a tool in Tableau Prep, select “Script”. A dialog opens, where you can specify your selection. You can choose between Rserve, which is an Rscript and Tableau Pyhton (TabPy) Server, which is a python script. Choose Tableau Python.

You will find the information “No Connection” and an explanation beneath. There was or still is a more complicated way, of setting up a connection, but there is also a very easy one. Click on “Help” in the menu, select “Settings and Performances” and then “Manage Analytics Extension Connection”.

Here you choose again the kind of script, you want to insert ( Rserve or TabPy ). As server you insert “localhost” and as port you type “9004”. You can leave the username and the password empty ( if you work in a company, there will probably be a password though ).

For the script you have to set up an actual R or Python script. For Pyhton, the script has to end with the file ending “.py”. Therefore you can use a tool like Jupyter Notebook for example, and first write your code as usual in a Jupyter Notebook file (ipynb). Think of putting your code snippets in functions, as in the end you need a function for the Tableau Prep workflow.

Then transfer your code to a script. For that, you can select over the menu button “New”  in Jupyter Notebook the option “Text File”. Save the file as name.py- it will be recognized, that it’s a python script and the code will be highlighted. Insert your code and make sure, that its one function, to start the whole workflow in the python script, that means one functions, which calls the other functions. Also make sure, that the function returns a pandas Dataframe as an Output.

Then all you have to do left, is to reference the script in Tableau Prep. Over the button “Browse”, browse for the python script file. Then under “Function name”, write the exact name of the function, which starts the workflow in the script.

That’s all. From here on, you can use the output of the function you wrote in Pyhton for prepping it further with Tableau Prep.

Author:
Viktoria Von Laer
Powered by The Information Lab
1st Floor, 25 Watling Street, London, EC4M 9BR
Subscribe
to our Newsletter
Get the lastest news about The Data School and application tips
Subscribe now
© 2025 The Information Lab