isin and between
isin tests membership and between tests a range.
Example
df = pd.DataFrame({"name": ["Ada", "Kofi", "Amina", "Tunde"], "country": ["NG", "GH", "NG", "NG"], "score": [92, 78, 85, 71]})
print(df[df["country"].isin(["GH"])]["name"].tolist())
print(df[df["score"].between(75, 90)]["name"].tolist())Result
['Kofi'] ['Kofi', 'Amina']
Exercise
Range test.
df.score.(70, 80)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.