Tsallaka zuwa abun ciki
Justice Tech School

isin and between

isin checks membership in a list. between checks a range and includes both ends by default.

Example
import pandas as pd
import numpy as np
df = pd.DataFrame({'name': ['Ada', 'Bob', 'Cy', 'Di'], 'age': [30, 25, 35, 28], 'city': ['Lagos', 'Accra', 'Lagos', 'Nairobi'], 'score': [88.5, 92.0, 79.5, 85.0]})
print(df[df['city'].isin(['Lagos', 'Accra'])]['name'].tolist())
print(df[df['age'].between(26, 30)]['name'].tolist())

Result

['Ada', 'Bob', 'Cy']
['Ada', 'Di']

Exercise

Check membership.

df["city"].(["Lagos"])

Quiz Test

Does between include the ends?

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