3 Replies Latest reply on Jul 20, 2018 3:49 PM by Nathan Mannheimer

    Python script not working in Tableau

    muhammad usman

      SCRIPT_REAL("

       

       

      from scipy.stats import linregress

       

       

      slope, intercept, r_value, p_value, std_err = linregress(_arg1, _arg2)

       

       

      return [slope*x + intercept for x in _arg1]

       

       

      ", SUM([Revenue ($)]), SUM([Units Sold]))

       

      This is the script that i am trying to run on Tableau but it shows the error "

      Unable to complete action

      An error occurred while communicating with the Predictive Service.

      An error occurred while communicating with the Predictive Service.

      Invalid JSON"

       

      I have checked the connection with Tabpy server its working fine

        • 1. Re: Python script not working in Tableau
          Nathan Mannheimer

          Hi Muhammad,

           

          What happens if you run this code while monitoring your TabPy console (curious to make sure that the list comprehension is making the right list):

           

          SCRIPT_REAL("

          from scipy.stats import linregress

          slope, intercept, r_value, p_value, std_err = linregress(_arg1, _arg2)

          print([slope*x + intercept for x in _arg1])

          return 1

          ", SUM([Revenue ($)]), SUM([Units Sold]))

           

          The results should look like a list of length len(Sum(revenue)).

           

          One thing to check it that the table calculation is set to address all fields.

           

          Sincerely,

          Nathan

          • 2. Re: Python script not working in Tableau
            muhammad usman

            the above code only returns 1
            the original print statement didn't work

            • 3. Re: Python script not working in Tableau
              Nathan Mannheimer

              Hi Muhammad,

               

              The print statement should print in the command line where you are running TabPy. This print out should confirm whether the results are formatted correctly or there is an issue with. Looking at similar situations where people have encountered this error, it is likely due to the way the table calculation is computed. You want to make sure that everything is on addressing so that the calculation runs on the full dataset. If it runs on one point at a time it will be undefined. The table calculation dialogue should look like this if you (for example) used Product Name as the level of detail in the visualization:

               

              Screen Shot 2018-07-20 at 3.33.01 PM.png

               

              I've attached a working example here!

               

              Sincerely,

              Nathan