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?
---------------------------------------------- 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)]