pythonvisualizationtableau-apitabpy

TabPy - Invalid file path or buffer object type


Started out with TabPy recently.

I have seen that python codes directly doesnt work inside Tableau (which usually runs well inside Python environment) or maybe I am doing something wrong.

Here is what I am facing -

I wrote the code

FLOAT(SCRIPT_REAL('

import pandas as pd
import numpy as np
from scipy import stats


# In[152]:

# Reading input file

data_file = pd.read_csv(_arg1)
a1 = data_file([Actualmax])
return a1' , '/User/****/caution new/7S.csv

# In[153]:

# Calculate Mean

mn = np.mean(a1)
return mn


'))

using this to find the mean from the column actualmax from the file 7S. The same code runs well inside Python but somehow I am getting an error message -

Error Message

After that, I even tried something like this - to use the Column as an argument instead of importing the file from the local system, because the file is already inside Tableau

INT(SCRIPT_STR("

import pandas as pd
import numpy as np
from scipy import stats

# In[152]:

# Reading input file

data_file = pd.read_csv(_arg1)

# In[153]:

# Calculate Mean

mn = np.mean(_arg1)
return mn

",SUM([Actualmax])))

There are no syntax errors but the error remains the same.

I get the result when I write something like this -

SCRIPT_INT("

import pandas as pd
import numpy as np
from scipy import stats

# In[152]:

# Reading input file

#data_file = pd.read_csv(arg)

# In[153]:

# Calculate Mean

mn = np.mean(arg)
return mn


",AVG([Actualmax]))

But this isn't something I want to go to - as it is using the AVG function inside Tableau and not the power of Python.

What am I doing wrong in here? How should I proceed?


Solution

  • Apparently the answer was pretty simple - I followed Bora Beran's post in the link given below - https://community.tableau.com/docs/DOC-10856

    under the section - Using Every Row of Data - Disaggregated Data

    The new code is

    (SCRIPT_REAL("
    
    import numpy as np
    # Normality test
    
    #return _arg1
    
    mn = np.mean(_arg1)
    return mn
    
    
    ",ATTR([Actualmax])))
    

    Hope this helps anyone else who was going through this issue.

    Happy Tableau'ing.