I'm using Tableau Prep with Python Script, however when I run the Python Script, I receive an error that says "prep int() function is not defined" in the Output Flow. For the get output schema function, I used prep int() in Python Script.
import pandas as pd
import requests
import json
df = pd.read_csv("E:/dummy.csv")
port = "8080"
target_columns = ["id"]
# target_columns = df['id']
source_columns = list(set(df.columns) - {"target"})
# print(target_columns)
target_json = json.loads(df[target_columns].to_json(orient="records"))
source_json = json.loads(df[source_columns].to_json(orient="records"))
# print(source_json)
payload = {"source": {"data": source_json}, "target": {"data": target_json}}
# print(payload)
# Run a single or mini-batch prediction
headers = {"content-type": "application/json", "accept": "application/json"}
r = requests.post(
"http://14.141.154.146:9871/invocations", data=json.dumps(payload), headers=headers
)
# print(r.text)
def filldata():
df = pd.DataFrame()
ID(int)
# fill df up with data
# for example
# name (string)
# time (datetime)
# number (int)
return df
def get_output_schema(self):
return pd.DataFrame({"ID": prep_int()})