I am trying to load a python data framework to Watson Function Action. I got the following error.
{ "error": "Internal error. Object of type module is not JSON serializable" }
I am loading a Watson Notebook Dataframe in Watson Function Action creating a function that returns a Json, from the notebook I test it and it works if the Json returns but I do not know if I need something in the function
Dataframe code
dfData = dfData[['SOURCE','NUMBER_ID','DATE_OPEN','DATE_CLOSE','COMPANY','CATEGORY','SUBCATEGORY','LOGICAL_NAME','CLR_TXT_SERVICIO','STATUS',]]
jsondf = dfData.to_dict(orient='record')
print(jsondf)
I have tried with:
#jsondf = dfData.to_json( orient='records')
print(jsondf)
#jsondf = jsondf.dumps(dfData, cls=JSONEncoder)
print(jsondf)
But none works
import sys
import types
import pandas as pd
import numpy as np
import ibm_boto3
import json as jsondf
import dateutil.relativedelta
from pandas import DataFrame
from botocore.client import Config
from datetime import datetime, date, time, timedelta
def main(dict):
def __iter__(self):
client_22e74e133ed74557a9183bca634893be = ibm_boto3.client(service_name='s3',
ibm_api_key_id='XXXXXXXXXXXXXXXXXXXXXXXXXXXX',
ibm_auth_endpoint="https://iam.bluemix.net/oidc/token",
config=Config(signature_version='oauth'),
endpoint_url='https://s3-api.us-geo.objectstorage.service.networklayer.com')
streaming_body_14 = client_22e74e133ed74557a9183bca634893be.get_object(Bucket='clarotp-donotdelete-pr-jfrmyss7bazrmn', Key='Vista_Mayo.xlsx')['Body']
# add missing __iter__ method so pandas accepts body as file-like object
if not hasattr(streaming_body_14, "__iter__"): streaming_body_14.__iter__ = types.MethodType( __iter__, streaming_body_14 )
#convertir el streaming body del archivo Excel a dataframe
def load_df(fileobject,sheetname):
excelFile = pd.ExcelFile(fileobject)
dfData = excelFile.parse(sheetname)
return dfData
#se crea el dateframe (dfData)
dfData = load_df(streaming_body_14, 'Exportar Hoja de Trabajo')
dfData = dfData[dfData['NUMBER_ID'].str.contains('IM1010935', case=False)]
jsondf = dfData.to_dict(orient='record')
return {'message': [jsondf] }
This is the function that I created but it does not work
Results:
{ "error": "Internal error. Object of type module is not JSON serializable" } Logs: []