What parameters are you passing to tabpy? Can you try adding .tolist() to your return(yy) like return(yy.tolist()) ? If this doesn't work, It may be beneficial for troubleshooting if you can attach your workbook and xlsx.
1 of 1 people found this helpful
I'm barely a Python user, but I do know Tableau fairly well, so hopefully I can help. Tableau's SCRIPT_ functions each return a single field, so if you are using SCRIPT_REAL then it's expecting to be given single number. I'm guessing the get_stats_all() function is returning a data frame and the error message that Tableau is generating is effectively saying that it can't turn the data frame into a single vector of numbers.
Assuming that's what's happening then there are two options:
1) Add another line or two of code to process the data frame to return a single field/vector's values. If you're looking to return multiple values from get_stats_all() then you'd need to have multiple calculated fields, each with their own call to a SCRIPT_ function.
2) The alternative would be to use a SCRIPT_STRING() - potentially with some extra code to format the output - so you can return a single string and then in downstream calculations parse out those results into separate numbers.
More generally I don't know what statistics the get_stats_all() is returning, if it's summary statistics then it's possible to build calculations in Tableau without using Python, so you might check that out.
Hope this helps!
Thank you for your response. You got it correct. It does returns a Dataframe with summarized statistics and yes it does returns multiple values.
About using tableau to calculate the stats, I am instructed to use python only.
1) using multiple SCRIPT_REAL doesn't seem ideal because the total number of stats returned are 22 (might increase in future)
2) I think SCRIPT_STRING is the way to go. I request you to please elaborate "potentially with some extra code to format the output - so you can return a single string and then in downstream calculations parse out those results into separate numbers. "
1 of 1 people found this helpful
In your Python code you'd need to turn the data frame into a string of numbers (and potentially text) with defined separators, maybe something like:
Then you'd need a set of N calculations (four in this example) to get each value, here's a screenshot:
As noted in the comment the formula is more complicated because (as of at least Tableau v2018.3) SPLIT, FINDNTH, and REGEX_EXTRACT_NTH aren't supported by table calculations (and the SCRIPT functions that Python is executed in are table calculations), vote up https://community.tableau.com/ideas/6239 if you'd like to get that.
Note that if the Python script is returning a changing number of variables in each run there's no automatic way to parse out into a variable number of calculated fields - you'll need to build as many calculations as you expect to have variables.
I've attached a v10.5 workbook I used to make the screenshot above.
PS: I know this is really painful, I had a conversation with a Tableau developer last month and I know they are looking into this. I'll also forward this thread as an example.
This is really helpful. Thanks a lot for the reply, appreciate it.