AmbifulWorksheets
Cheat sheet
CBSE · Class 12 · Informatics Practices

Data Handling using Pandas – I

pandas Series and DataFrames: making them, selecting with loc and iloc, filtering, changing and saving them.

Key ideas

Remember

Labels a to fs.loc['b':'d'] → b, c, d; s.iloc[1:3] → b, c
Some columnsdf[['Name', 'Maths']] (two pairs of brackets)
shape (r, c), size r × cadd a column: c + 1; drop a row: r − 1; drop a column: c − 1

Watch out

Worked example

Series s:
a | 38
b | 96
c | 75
d | 29
e | 61
f | 56
Write the output of each statement, and say why they differ.
(a) print(s.loc['b':'f'])
(b) print(s.iloc[1:5])

Working: loc slices by label (end included); iloc by position (end left out)

Answer: (a)
b | 96
c | 75
d | 29
e | 61
f | 56
(b)
b | 96
c | 75
d | 29
e | 61
loc includes the end label f; iloc stops before position 5.