First-Four-Rows-Of-Csv

Sat 17 May 2025

title: "First Four Rows of CSV" author: "Rj" date: 2019-04-22 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.shape
(9, 3)
dfr = df.iloc[:4]
dfr
capacity score length
0 1 10 30
1 2 20 30
2 3 30 40
3 3 40 30
# Get first four columns and 2 columns

dfr2 = df.iloc[:4, :2]
dfr2
capacity score
0 1 10
1 2 20
2 3 30
3 3 40

Score: 5

Category: data-wrangling