Jump to content

I encountered an error when using attribute 'set_spotfire_types' operation empty columns, it's look like the attribute not work. How do I use the attribute correctly?


Li Mingchao

Recommended Posts

I don't know what your specific data frame contains. This test code worked for me. The dictionary is meant to contain column names and respective datatypes, but there is no column named 'EmptyString' in your data frame, maybe that is the source of the problem you are seeing.

import pandas as pdimport spotfire df=pd.DataFrame(columns={'a','b','c'})spotfire.set_spotfire_types(df, {'a':'String','b':'Integer','c':'Real'})
Link to comment
Share on other sites

Thank you Gaia,I see what you mean. I thought before that I didn't need to specify the column name and format. When a column was empty, it was automatically set to string format. Because I have over a hundred columns in my data and it's hard to determine which ones are null, I want to use this property to avoid errors caused by null columns. Do you have any good advice for this situation

Link to comment
Share on other sites

I extended my previous example, seems to work. However, I cannot guarantee this is the expected way to use this package.

  • I created a data frame with columns a, b, c, d.
  • Columns b and c are left empty.
  • Columns a and d are assigned, respectively, a string and a real number.
  • Then I create the list of empty columns, and only to those I assign a Spotfire data type of 'String'.

It did correctly assign the data type to b and c within the script. The remaining, non empty columns, a and d where then assigned their proper Spotfire datatype upon returning the data frame to Spotfire.

import pandas as pdimport spotfire df=pd.DataFrame(columns={'a','b','c','d'})df['a']=['hello']df['d']=[3.567] empty_cols = [col for col in df.columns if df[col].isnull().all()] for col in empty_cols: spotfire.set_spotfire_types(df, {col:'String'})
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...