0

I am working on a project in Tableau- ver 10.4.2. My data is in a SQL Cube - and the columns I am working with are formatted as: MemberID - this is a string field with a member ID AdmissionDate - This is a DateTime field with format mmddYYYY DischargeDate - This is a DateTime field with format mmddYYYY

What I am trying to accomplish is this - I need to find instances where the patient was discharged, and then re-admitted within the ensuing 30 days. So, I need the difference of the Discharge date and the NEXT admission date, per patient (memberID). There are multiple admit & discharge dates for each MemberID (patient).

I thought an easy solution would be to shift the column for admission dates up by 1, using pandas... (I am running a TabPy server instance on my computer and it is functioning properly) - for each memberID - but keep running into errors like this - "TypeError : Object of type Series is not JSON serializable"

My script is

SCRIPT_REAL("
import pandas as pd
df = pd.DataFrame({'MemberID': _arg1,'AdmitDate': _arg2})
df['AdmitDate'] = pd.to_datetime(df['AdmitDate'])
MemberID = df.MemberID

for i in MemberID:
    newadmitdate = df.AdmitDate.shift(-1)
    return newadmitdate

",
ATTR([GR2MCL Member ID]),attr([AdmitDateCalc])
)

To troubleshoot, I created a csv file formatted similarly - and can see that my script is shifting the column properly. The only issue I can see is that it is not looping properly on each MemberID, but I am not getting errors like I am getting in Tableau.

Any thoughts on this would be appreciated!

Mike Heitz
  • 21
  • 8
  • Please show the full traceback of the initial error. I'm not sure how you've pinned the issue specifically on `shift()`. – roganjosh Jan 29 '18 at 21:51
  • Not sure I am pinning it on shift()... since it's working in a Spyder terminal window, i am not sure what's causing it. It's my first ever attempt at running a Python script in Tableau, so I am possibly mis-interpreting the error... here is the error from Tableau, trying to figure how to embed a screenshot of the error in Tabpy-server... TypeError : Object of type Series is not JSON serializable – Mike Heitz Jan 29 '18 at 22:07
  • The error (and traceback) I have requested. But how is "Tableau with Python Script - Pandas SHIFT function issue" _not_ pinning it on that function? – roganjosh Jan 29 '18 at 22:08
  • No, please don't embed an image of the error. You should include the full traceback as text in the question, as an edit, so that it is stand-alone. Any links to images might expire. – roganjosh Jan 29 '18 at 22:10
  • it's a plea for help & advice, not an accusation of the function... lol...here is a copy & paste of the output in TabPy-server screen - TypeError : Object of type Series is not JSON serializable ERROR:__main__:{"info": "TypeError : Object of type Series is not JSON serializable", "ERROR": "Error processing script"} ERROR:tornado.access:500 POST /evaluate (::1) 4105.00ms – Mike Heitz Jan 29 '18 at 22:12

0 Answers0