0

I'm trying to do Simple Random Sampling of a data in tableau using python by Tabypy server.

This is my code

SCRIPT_REAL(
"import pandas as pd
test=pd.DataFrame({'Case': _arg1,'fdr': _arg2,'site': _arg3,'acct': _arg4,'daykey':_arg5})

group=test.groupby(['Case','site'])

testing=group.apply(lambda x: x.sample(n=8,replace=True))

testing.drop_duplicates(keep=False,inplace=True)

testing.daykey=testing.daykey.astype('str')

return testing[_arg8]",
ATTR([R0 Type]),ATTR([Fdr Id]),ATTR([Agency name]),ATTR([Acct Id]),ATTR([Day key]),[Parameter 1])

But i'm getting the error

ValueError : not enough values to unpack (expected 2, got 0)

Thanks for the help

sir psycho sexy
  • 780
  • 7
  • 19
  • 1
    When you call a Tableau function that begins with the word SCRIPT, you are actually passing *vectors* as arguments to an external function written in Python, R or Matlab. Tableau expects the return result from that function to have the same cardinality as the vectors you pass as arguments. So if you pass vectors of length 2 as arguments and return a vector of length 0, then Tableau will not be happy with the result. Script functions are forms of Tableau table calcs. Read about table calcs in the on-line help, and make sure you understand the concept of partitioning and addressing. – Alex Blakemore May 27 '19 at 18:30
  • Can you edit the question...I only see 6 arguements passed to tabpy, but there are up to `_arg8` in the script. Have you tried to run the code passing test data in python alone to troubleshoot any python errors before using tableau and tabpy? – jtweeder Aug 27 '19 at 01:23

0 Answers0