0
$\begingroup$
def CTDataSQ (name):
    name= cleanDF[["PatientstudyId2","RATER","CT_3D",name]]
    name= name.loc[name['CT_3D'] == 1]
    del name["CT_3D"]
    name.to_excel(name, ".xlsx") 
    
    
for y in Questions:
    CTDataSQ(y)

I'm attempting to create a function that creates excel spreadsheet outputs with names derived from a list. I get the following error.

UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U32'), dtype('<U32')) -> dtype('<U32')

Looked online and cannot seem to solve. Any help would be appreciated.

Thanks

$\endgroup$

1 Answer 1

1
$\begingroup$

First of all, as indicated in the pandas documentation, the to_excel method have a first parameter that accepts a str or an ExcelWriter object. In your case I assume you're trying to pass a str. In this case, it is not possible to pass name as the parameter because it is not a str, it is a pandas.DataFrame since there is:

name = name.loc[name['CT_3D'] == 1]

I suppose you're trying to pass a column name (str), filter by another one (CT_3D), assign it to a new final df and save it. I'd do the following for that:

def CTDataSQ (col_name):
    final_df= cleanDF[["PatientstudyId2","RATER","CT_3D",col_name]]
    final_df= final_df.loc[final_df['CT_3D'] == 1]
    del final_df["CT_3D"]
    final_df.to_excel(col_name + ".xlsx") 
    
    
for y in Questions:
    CTDataSQ(y)

This way, it is better diferentiated the column name from the dataframe. And as you can see, you have to concatenate the strings col_name with the extension (.xlsx) with a + sign, not separate them by a comma (since it is considered as another parameter for .to_excel).

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.