Error: " not supported for the input types "

Hello, I am selecting subsets of a dataframe, and used .fillna() the first time around to clear out the NaN’s by replacing them with “No Response”. The second time around I tried to use .isfinite(). In both instances, I get "… not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ‘‘safe’’ ". Any tips on how to navigate through this error? :sweat_smile:

---------------------------------------------- Try #1------------------------------------
dataone = data.iloc[:,[19,17]]

gender_male = dataone[dataone[“Gender (optional)”]== ‘Male’] #There are 12573 Male ; Column 19-1=18
gender_female = dataone[dataone[“Gender (optional)”]== ‘Female’] #There are 45300 Female
#null_count = data[“Gender (optional)”].isnull().sum() #1618 null-values

##----Filling missing data with “No Response”
cleaned_gender = dataone[“Gender (optional)”].fillna(‘No Response’, inplace=True)
##----Checking that the sum of the null’s is zero ; meaning no nulls there
null_count = dataone[“Gender (optional)”].isnull().sum()

#fig, ax = plt.subplots()
#ax.scatter(gender_male, gender_female)

question = dataone[“Do you openly discuss salary with your colleagues?”].unique() #Columns 17-1 = 16
cleaned_question = dataone[“Do you openly discuss salary with your colleagues?”].fillna(‘No Response’, inplace=True)

##---- Mann-Whitney
testman = mannwhitneyu(gender_male, gender_female, alternative=‘two-sided’)

----------------------------------------------------Try #2--------------------------------------
#Columns of interest
dataone = data.iloc[:,[19,17]]

#Grabbing Gender:
gender_male = dataone.loc[dataone[“Gender (optional)”]== ‘Male’]
gender_female = dataone.loc[dataone[“Gender (optional)”]== ‘Female’]

questionwmale = np.array(gender_male[“Do you openly discuss salary with your colleagues?”])
questionwfemale = np.array(gender_female[“Do you openly discuss salary with your colleagues?”])

datafem = questionwfemale[np.isfinite(questionwfemale)]
datamal = questionwmale[np.isfinite(questionwmale)]

So what type is the array being passed to np.isfinite? I think it only ever works on numbers.

As an aside How do I format code in my posts? is worth a look as it keeps better code formatting on the forums. Linking the relevant lesson/project/data source might be useful here too to eliminate some guesswork.

2 Likes