Value_counts() returning no NaN values, but repeat True values

When I apply value_counts to tafe_resignations_up with dropna=False, The values I see are False, True, and True (not NaN). Why is this happening? Is there a way to prevent this?

Screen Link: Learn data science with Python and R projects

My Code:

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

tafe_resignations_up['dissatisfied'].value_counts(dropna=False)

I would recommend checking existing posts about similar issues -

@the_doctor I am working off of my local machine. How do I upgrade pandas in this case? Do I have to use the terminal?

That would depend on your OS and other factors that I can’t help with since it’s a local installation.

I would recommend simply googling for updating pandas for your OS and you should find tutorials that can help you out.

If it’s difficult or overwhelming for you, I would recommend either completing the project on DQ’s platform or creating a new, separate question asking specifically about updating Pandas version with details related to your local installation - like the OS, what you have tried so far, what package manager you might be using on your system etc.

any returns True if at least 1 value is True. Otherwise return False.

You can read up on documentation any on your local machine using

import pandas pd
help(pd.Series.any)

or using

help(tafe_resignations[tafe_dissatisfaction_cols].applymap(update_vals).any)

To count the number of True, you can use .sum() since True has a value 1 and False has a value of 0 – this is because Boolean is subclass of int. Then, number of False = length of data frame or series - number of True.

1 Like

thanks for solving this for me- i forgot I applied the any method and shouldn’t expect to see NaN anyway!