Index Isin

Sat 17 May 2025

title: "Index isin" author: "Rj" date: 2019-04-24 description: "-" type: technical_note draft: false source: http://pandas.pydata.org/pandas-docs/version/0.24/user_guide/cookbook.html#idioms


import numpy as np
import pandas as pd
df = pd.DataFrame({
    'maths' : [80, 89, 90, 20, 60],
    'science' : [40, 50, 90, 100, 50],
    'language' : [20, 30, 90, 95, 40]
})
df
maths science language
0 80 40 20
1 89 50 30
2 90 90 90
3 20 100 95
4 60 50 40
df[df.index.isin([1, 2, 4])]
maths science language
1 89 50 30
2 90 90 90
4 60 50 40


Score: 5

Category: data-wrangling