Project Question

Screen Link:
https://app.dataquest.io/m/348/guided-project%3A-clean-and-analyze-employee-exit-surveys/4/filter-the-data

My Code:

dete_resignations = dete_survey_updated[dete_survey_updated['separationtype'] == "Resignation-Other reasons"][dete_survey_updated['separationtype'] == "Resignation-Other employer"][dete_survey_updated['separationtype'] == "Resignation-Move overseas/interstate" ]].copy()

What I expected to happen:
the dete_survey_updated dataframe contains three Resignation separation types. We want to select all of them.

What actually happened:

error```

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

This is the tafe solution tafe_resignations = tafe_survey_updated[tafe_survey_updated['separationtype'] == 'Resignation'].copy()

however the dete one includes more elements

hi @federico1

I don’t understand how you got this idea? :thinking:

I will try to make it easy for both of us to work on this. There are two ways you can extract all types of “Resignation”:

  1. in your code instead of assigning multiple copies of dataframes to one single dataframe (yup you might be doing that here! break your code and see), you can combine the conditions with | (symbol for or) as in:

df = df[(df.col == type1) | (df.col == type2) | and so on]

  1. In the prior missions, you might have come across .str.contain(pattern) try to review this code part and then device your solution.
2 Likes

Thanks, it did help a lot!

1 Like

Hi Rucha,

I’m not sure how to use the second method

pattern = 'Resignation-Other reasons' or 'Resignation-Other employer' or 'Resignation-Move overseas/interstate'

resignation = dete_survey_updated['separationtype'].str.contains(pattern)

The result only returns rows with ‘Resignation-Other reasons’ and not the other two. Am I using the or operator incorrectly?

hi @dgny90

thank you for asking this question and that too pointedly at me. I am hardly getting any chance to respond post the Learning assistant Prog. :stuck_out_tongue:

Have you tried printing the pattern variable after you have declared it? Direct answer - yup the usage of or here is wrong.

It’s like code is giving choice to pattern variable to pick one among the 3 and since it’s OR it takes the first value. Change OR to AND see the difference!

1 Like