+1 vote
in Python by
Given a dataframe of students’ favorite colors and test scores, write a function to select only those rows (students) where their favorite color is green or red and their test grade is above 90.

1 Answer

0 votes
by

We need to filter our dataframe by two conditions: grade and favorite color. We can filter our dataframe by grade by setting our dataframe equal to itself with the condition that the grade column is greater than 90:

students_df = students_df[students_df["grade"] > 90]

Now we want to do the same process for favorite color, but the problem is that we have two possible categories for inclusion in the filtered dataframe. How can we write code to include both possibilities in our final dataframe?

Related questions

0 votes
asked Feb 11, 2021 in Python by SakshiSharma
+1 vote
asked Oct 28, 2022 in Python by SakshiSharma
...