Recall & Review
beginner
What is the purpose of selecting rows by condition in pandas?
Selecting rows by condition helps you filter data to keep only the rows that meet specific criteria, making it easier to analyze relevant information.
Click to reveal answer
beginner
How do you select rows where a column 'Age' is greater than 30 in a pandas DataFrame named df?
Use df[df['Age'] > 30] to get all rows where the 'Age' column value is greater than 30.
Click to reveal answer
beginner
What does the expression df[df['Score'] >= 80] return?
It returns a new DataFrame containing only the rows where the 'Score' column is 80 or higher.
Click to reveal answer
intermediate
How can you select rows where column 'City' is either 'New York' or 'Chicago'?
Use df[df['City'].isin(['New York', 'Chicago'])] to select rows where 'City' is one of the listed values.
Click to reveal answer
intermediate
What is the difference between using & and | operators in pandas conditions?
& means AND (both conditions must be true), | means OR (at least one condition must be true). Remember to use parentheses around each condition.
Click to reveal answer
Which code selects rows where 'Salary' is less than 50000?
✗ Incorrect
df[df['Salary'] < 50000] filters the DataFrame to keep rows where 'Salary' is less than 50000.
How do you select rows where 'Age' is between 20 and 30 inclusive?
✗ Incorrect
Use & with parentheses: df[(df['Age'] >= 20) & (df['Age'] <= 30)] or use df[df['Age'].between(20, 30)] to select rows where Age is between 20 and 30.
What does df[df['Status'] == 'Active'] do?
✗ Incorrect
It filters the DataFrame to keep only rows where the 'Status' column equals 'Active'.
Which method helps select rows where a column matches any value in a list?
✗ Incorrect
The isin() method checks if values in a column are in a list of values.
How do you combine two conditions to select rows where 'Age' > 25 OR 'Score' > 90?
✗ Incorrect
Use | for OR with parentheses: df[(df['Age'] > 25) | (df['Score'] > 90)].
Explain how to select rows in a pandas DataFrame based on a condition involving a single column.
Think about how you write conditions like 'Age > 30' inside the brackets.
You got /3 concepts.
Describe how to combine multiple conditions to filter rows in pandas.
Remember to use parentheses and the right logical operators.
You got /3 concepts.