1

I am trying to make a pivot_table(crostab) calculation and find the result

In Python, my data-frame variables are like this

pd.crosstab(columns=df['user'],index=df['date'],values=df['latest_balance'], aggfunc='sum').ffill().sum(axis=1).reset_index()

and result:

enter image description here

when I add into tableau like this:

SCRIPT_REAL("
import pandas as pd 
import numpy as np


pd.crosstab(columns=_arg1,index=_arg2,values=_arg3, aggfunc='sum').ffill().sum(axis=1)




",
ATTR([user]),
ATTR([date]),
ATTR([latest_balance]) )

I am getting:

Error processing script
ValueError : If using all scalar values, you must pass an index

I am pretty new python with tableau so sorry if it is a silly question.

martineau
  • 119,623
  • 25
  • 170
  • 301
Axis
  • 2,066
  • 2
  • 21
  • 40
  • Take a look at the answer I proposed for this question. Similar issue and my answer provides a pretty good walk through. https://stackoverflow.com/questions/56400669/tableau-error-all-fields-must-be-aggregate-or-constant-when-invoking-tabpy-scr/57630268#57630268 – jtweeder Aug 26 '19 at 19:50
  • Thank you for comment, now I am having ```TypeError : Object of type Series is not JSON serializable``` – Axis Aug 26 '19 at 20:23
  • That is because you are trying to send a dataframe/table back. There should be a specific function or calculation on that data that is returned to tableau from tabpy. See their documentation. Either it returns the same number of rows passed, or sends multiple columns, and gets one value back. https://github.com/tableau/TabPy/blob/master/docs/TableauConfiguration.md – jtweeder Aug 27 '19 at 01:13

0 Answers0