top of page

Data Scientist Program


Free Online Data Science Training for Complete Beginners.

No prior coding knowledge required!

Pandas Technique-Subsetting

import pandas as pd
import numpy as np

Read Dataset

df = pd.read_csv('Srt_dta.csv')df

Subsetting columns

To select a single column, use square brackets [] with the column name of the column of interest.


Subsetting multiple columns

# method 1

# method 2
cols_to_subset = ["Breed","Height(cm)"]

Subsetting rows

This return boolean value.

df["Height(cm)"] > 50

# This return numeric value
df[df["Height(cm)"] > 50]

Subsetting based on text data

df[df["Breed"] > '2015-01-01']

Subsetting based on multiple conditions

is_lab = df['Breed'] == 'Labrador'
is_black = df['Color'] == 'Black'
df[is_lab & is_black]

Subsetting using .isin()

Pandas isin() method is used to filter data frames. isin() method helps in selecting rows with having a particular(or Multiple) value in a particular column. Parameters: values: iterable, Series, List, Tuple, DataFrame or dictionary to check in the caller Series/Data Frame.

is_black_or_brown = df['Color'].isin(['Black', 'Brown'])


Recent Posts

See All
bottom of page