Python Practice › Pandas Programs › Program 24
Items at positions
Write a pandas program to extract items at positions 1, 4 and 7.
Input
[3, 0, 3, 2, 2, 0, 3, 3, 2]
Output
1 0 4 2 7 3 dtype: int64
Approach
ilocwith a list.
Solution
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
Learn the concept
New to this topic? Read the lesson, then come back.