Tsallaka zuwa abun ciki
Justice Tech School

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

How do you use a variable in query?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.