query
query filters with a string expression.
Example
df = pd.DataFrame({"name": ["Ada", "Kofi", "Amina", "Tunde"], "country": ["NG", "GH", "NG", "NG"], "score": [92, 78, 85, 71]})
print(df.query("score > 80 and country == 'NG'")["name"].tolist())
min_s = 75
print(df.query("score >= @min_s").shape[0])Result
['Ada', 'Amina'] 3
Exercise
Filter by text.
df.("score > 80")
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.