head, tail and sample
head shows the first rows, tail the last and sample picks random rows.
Example
df = pd.DataFrame({"name": ["Ada", "Kofi", "Amina", "Tunde"], "country": ["NG", "GH", "NG", "NG"], "score": [92, 78, 85, 71]})
print(df.head(2))
print(df.tail(1))
print(df.sample(2, random_state=1).shape)Result
name country score
0 Ada NG 92
1 Kofi GH 78
name country score
3 Tunde NG 71
(2, 3)Exercise
First rows.
df.(2)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.