Guided Project: Clean and Analyze Employee Exit Survey step 7 .any()

I need some help on step 7 in the Clean and Analyze Employee Exit Survey. I’ve figured out most of the ‘difficult’ problems, but once I’ve created the tafe_resignations[‘dissatisfied’] column I can’t seem to get .any() to return the correct value. df.any() seems to only be looking for true values in one column of the data frame rather than both columns of the dataframe

My Code:

// This code will take the values in two columns and replace any '-' with False
// if the value is null it will be replaced with np.nan
// if the value is anything else it will be replaced with True

def update_val (val):
    if val == '-':
        return False
    elif (pd.isnull(val)):
        return np.nan
    else:
        return True
    
tafe_resignations['Contributing Factors. Dissatisfaction'] = tafe_resignations['Contributing Factors. Dissatisfaction'].apply(update_val)
tafe_resignations['Contributing Factors. Job Dissatisfaction'] = tafe_resignations['Contributing Factors. Job Dissatisfaction'].apply(update_val)

tafe_resignations['Contributing Factors. Job Dissatisfaction'].value_counts()
-                      270
Job Dissatisfaction     62
//The above code does what I expect to happen. Here are the outputs before/after: 

Output:
 
//Before using .apply(): 

tafe_resignations['Contributing Factors. Job Dissatisfaction'].value_counts()

//-                      270
//Job Dissatisfaction     62
//Name: Contributing Factors. Job Dissatisfaction, dtype: int64

//After using .apply(): 

tafe_resignations['Contributing Factors. Job Dissatisfaction'].value_counts()

//NaN     285
//True     55

// '-' has been replaced with NaN and 'Job Dissatisfaction has been replaced with True

//Before using .apply(): 

tafe_resignations['Contributing Factors. Dissatisfaction'].value_counts()

//NaN     285
//True     55

After using .apply(update_val)

tafe_resignations['Contributing Factors. Dissatisfaction'].value_counts()


What I expected to happen:


What actually happened: 

Replace this line with the output/error


<!--Enter other details below: -->

Hi @smits.ryan and welcome to the community!

Just as an FYI, it’s always good to provide a link to the screen you’re having trouble with so that others can get a bit more context on your problem. I manually navigated my way to this screen and here is the link for convenience: Learn data science with Python and R projects

First first thing that jumps out at me here is that you’re using df.apply() as opposed to df.applymap() as the Instructions tell us to do. Also, I do not see where you create the column dissatisfied for each df. For example, for the tafe df, your code should look like this:

tafe_resignations['dissatisfied'] = tafe_resignations[['Contributing Factors. Dissatisfaction', 'Contributing Factors. Job Dissatisfaction']].applymap(update_vals).any(1, skipna=False)