1 Reply Latest reply on May 28, 2019 12:25 PM by Nathan Mannheimer

    Using Python in tableau

    ishani chheda

      Hi Community,


      I have created a code in python to predict the probability of the product being sold or not, I want to integrate it in tableau. I have followed the same steps as : Leverage Tableau and Python to build advanced-analytics applications.

      I am using the breast cancer example.

      I am writing the code in jupyter notebook.

      I have also created a calculated field in tableau :

      SCRIPT_STR("return tabpy.query('Demo','_arg1','_arg2','_arg3','_arg4','_arg5','_arg6')['response']",

      [Parameters].[Customer Name],[Parameters].[Sales],[Parameters].[Profit],[Parameters].[City],[Parameters].[Postal Code],[Parameters].[Sub-Category],[Parameters].[Quantity])


      When I am dragging this calculated field in tableau, I am getting this error;

      Unable to complete action

      An error occurred while communicating with the External Service.

      Error processing script

      The endpoint you're trying to query did not respond. Please make sure the endpoint exists and the correct set of arguments are provided.


      I have read few blogs and community pages , the solution there provided is;

      "Most likely answer is that the model wasn't successfully trained. When this happens, you can still publish a function to TabPy server but the error will surface when you try to run the model. On some Windows machines, this could happen due to a bug in Python when you try to run model fitting by using all the CPU cores you have. This is controlled by the "n_jobs=-1" setting in the Jupyter workbook. I suspect this might be the issue.

      The solution is to set n_jobs=1 which will run the training using only a single core. After making this, if you add the argument override=True to your deploy function then run the entire Jupyter workbook (Cell > Run All) I suspect it might fix it."


      My question is how do we solve this? And when it is said the model isn't successfully trained what is meant by it? And how do I set the n_jobs=1?

      Help is much appreciated.


      Thank you,

      Ishani Chheda

        • 1. Re: Using Python in tableau
          Nathan Mannheimer

          Hi Ishani,


          I think the issue here is that you are passing parameters to your model, which when sent from Tableau are included in Python lists. Assuming your model expects individual strings (ie a Customer Name) you will need to pull these out of the list in your code. In the case of parameters, the lists will have constant values, and if there is no other detail on the view, the list will only have one element. This you can just pull the first value, index 0, out of the list to pass to your model. You also do not need to wrap the parameters in quotes, as the type will be brought over, assuming those parameters are string types in Tableau.


          Try formatting your function like this (note that I am pulling index 0 out of each list):


          SCRIPT_STR("return tabpy.query('Demo',_arg1[0],_arg2[0],_arg3[0],_arg4[0],_arg5[0],_arg6[0])['response']",

          [Parameters].[Customer Name],[Parameters].[Sales],[Parameters].[Profit],[Parameters].[City],[Parameters].[Postal Code],[Parameters].[Sub-Category],[Parameters].[Quantity])