Python Practice › Pandas Programs › Program 16

Subset by condition

EasyPandas Programs · 16 of 95

Write a pandas program to select the values below 40.

Advertisement
Input
[10, 25, 69, 74, 33, 54, 21]
Output
0    10
1    25
4    33
6    21
dtype: int64

Approach

  1. Boolean indexing.

Solution

Python
import pandas as pds = pd.Series([10, 25, 69, 74, 33, 54, 21])print(s[s < 40])
Output
0    10
1    25
4    33
6    21
dtype: int64
Advertisement

Learn the concept

New to this topic? Read the lesson, then come back.

More pandas programs

← All 95 Pandas Programs