head/tail & Statistics
🎬 Watch the 3:55 video of this topic ↓Once you have data, you'll want to peek at it and summarise it. Pandas gives you one-liners for both — from head() to a full describe().
1Peeking with head() & tail()
Big tables are unwieldy — head(n) shows the first n rows and tail(n) the last. Both default to 5.
2Summaries run along an axisOptional Reading
Functions like sum(), mean(), max() and min() collapse the table. The axis argument decides the direction:
| Call | Direction | Answers |
|---|---|---|
| df.sum() | axis=0 (default) — down each column | one number per column |
| df.sum(axis=1) | across each row | one number per row |
count() even tells you how many real (non-NaN) values each column has.3The all-in-one: describe() & info()Optional Reading
describe() reports count, mean, std, min, the quartiles and max for every numeric column in one shot. info() summarises the structure — columns, non-null counts and dtypes.
4Statistics on a subsetOptional Reading
The real trick: first select a row, column or subset (with the tools from the earlier lessons), then apply the function to just that piece.
head()/tail(). Summarise with sum/mean/max/min/count — axis=0 works down columns, axis=1 across rows — or get everything with describe(). Select first to summarise a subset.production.sum(axis=1) gives you…
A column has one NaN. What does df['col'].sum() do with it?
DataFrame: head, tail and Statistics, in 3:55
One animated video of this topic, narrated. Watch it before the lessons for the big picture, or after them to revise.
🔊 Hindi mein sunna hai? Watch on YouTube with Hindi audio ↗(there, choose ⚙ Settings → Audio track → Hindi)