Python Practice › Pandas Programs › Program 24

Items at positions

EasyPandas Programs · 24 of 95

Write a pandas program to extract items at positions 1, 4 and 7.

Advertisement
Input
[3, 0, 3, 2, 2, 0, 3, 3, 2]
Output
1    0
4    2
7    3
dtype: int64

Approach

  1. iloc with a list.

Solution

Python
import pandas as pds = pd.Series([3, 0, 3, 2, 2, 0, 3, 3, 2])print(s.iloc[[1, 4, 7]])
Output
1    0
4    2
7    3
dtype: int64
Advertisement

Learn the concept

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

More pandas programs

← All 95 Pandas Programs