Jump to content

I have written a data function to retrieve data from an API. I have used the information in the response to create a pandas data frame and I have set the dtype for each column. Spotfire does not use this typing and then fails when trying to auto assign.


Bill Hall

Recommended Posts

I have written a data function to retrieve data from an API. I have used the information in the response to create a pandas data frame and I have set the dtype for each column. Spotfire does not use this typing and then fails when trying to auto assign.
Link to comment
Share on other sites

That worked for me, thank you for your quick response. I included a snippet of my code in case someone else finds this in the future.

data_set = myapi.Dataset.get_by_full_path(data_path)

field_info = data_set.fields()

returned_data_set = data_set.query()

pd_field_list = {}

sf_field_list = {}

pd_data_type_map = {

  "string":"object",

  "text":"object",

  "auto":"object",

  "integer":"int64",

  "long":"int64",

  "double":"float64",

  "float":"float64",

  "boolean":"bool",

  "date":"datetime64"

}

sf_data_type_map = {

  "string":"String",

  "text":"String",

  "auto":"String",

  "integer":"Integer",

  "long":"LongInteger",

  "double":"Real",

  "float":"Real",

  "boolean":"Boolean",

  "date":"DateTime"

}

for field in field_info:

  pd_field_list[field.name]=pd.Series(dtype=pd_data_type_map.get(field.data_type,"object"))

  sf_field_list[field.name]=sf_data_type_map.get(field.data_type,"String")

qp_data_set = pd.DataFrame(returned_data_set, columns = pd_field_list)

spotfire.set_spotfire_types(qp_data_set, sf_field_list)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...