Each run starts with fresh data. Download any exported files before another run. Your written answers and code drafts are saved on this device; export your work to keep a backup.
M06C01 · Explore · predict · practice
See the True and False values first
Comparing a Series with a value produces a Boolean Series, often called a mask. Each True marks a row that meets the condition. df.loc[mask, columns] keeps those rows and selects the requested columns. Keeping the mask in its own variable makes the logic easier to inspect.
Dana, Hassan, and Khalid match the new rule, giving three rows. The question changed from high scores to scores needing attention.
Compare your explanations
Read. A Boolean value, True or False, for this clean non-missing Score column.
Predict. Six: S001, S003, S006, S007, S010, and S012.
Explain. It only contains the condition results. A second selection uses that mask to retrieve the matching records.
One quick check
What does a True in a filter mask mean?
What you should be able to explain. I can separate the condition from the table selection it controls.
M06C02 · Explore · predict · practice
Combine conditions with AND and OR
Use & for element-by-element AND and | for element-by-element OR. Put parentheses around each comparison before combining them. AND requires both conditions; OR requires at least one. Python's and and or do not combine pandas Series masks this way.
All six RAK students qualify, and Fatima qualifies through her score of 95. Chloe meets both conditions but appears only once, so there are seven rows.
Compare your explanations
Read. Its Campus must equal RAK and its Score must be at least 80.
Predict. Amira, Chloe, and Grace.
Explain. A student can pass either condition: be at RAK, have Score at least 80, or satisfy both. More rows can qualify.
One quick check
Which correctly combines two pandas conditions with AND?
What you should be able to explain. I can translate both, either, and at least into correct filter logic.
M06C03 · Explore · predict · practice
Membership, ranges, and NOT
isin() tests whether a value belongs to an allowed list. between() checks a range; inclusive="both" includes its two endpoints. The ~ operator reverses a Boolean mask. Naming masks can make a longer rule easier to explain.
Bilal, Ethan, Ivy, and Lina qualify. ~ reverses the AI membership test before the score range is applied.
Compare your explanations
Read. Include values exactly equal to 70 or 90, as well as values between them.
Predict. Amira, Grace, and Jamal.
Explain. isin expects a list-like collection of allowed values. The same expression can later include several categories.
One quick check
Which operator reverses a Boolean Series?
What you should be able to explain. I can express allowed categories, numerical ranges, and excluded categories.
M06C04 · Explore · predict · practice
Read a filter written with query
query() is another way to express a row filter, using a short expression in a string. Column names appear inside that expression. @limit refers to a Python variable outside it. Learn the normal Boolean-mask form first so you can check what the query means.
Read the example
df = students()
limit = 85
result = df.query("Score >= @limit and Campus == 'Dubai'")[["Name", "Campus", "Score"]]
print(result)