Iloc-Position-Slice
Sat 17 May 2025
title: "iLoc Position Slice" author: "Rj" date: 2019-04-24 description: "-" type: technical_note draft: false
import numpy as np
import pandas as pd
df = pd.read_csv('data1.csv')
df
| capacity | score | length | |
|---|---|---|---|
| 0 | 1 | 10 | 30 |
| 1 | 2 | 20 | 30 |
| 2 | 3 | 30 | 40 |
| 3 | 3 | 40 | 30 |
| 4 | 2 | 30 | 40 |
| 5 | 7 | 10 | 23 |
| 6 | 3 | 20 | 22 |
| 7 | 8 | 20 | 11 |
| 8 | 2 | 30 | 2 |
df.iloc[2:8]
| capacity | score | length | |
|---|---|---|---|
| 2 | 3 | 30 | 40 |
| 3 | 3 | 40 | 30 |
| 4 | 2 | 30 | 40 |
| 5 | 7 | 10 | 23 |
| 6 | 3 | 20 | 22 |
| 7 | 8 | 20 | 11 |
df.iloc[8]
capacity 2
score 30
length 2
Name: 8, dtype: int64
df.iloc[7]
capacity 8
score 20
length 11
Name: 7, dtype: int64
Score: 5
Category: data-wrangling