Reputation: 21
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!
Upvotes: 0
Views: 279