Informatics Practices · Class 12 · Python Pandas · DataFrame
PandasDataFrame⏱️ 9 min read
head/tail & Statistics
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.
df_head_tail.py
2Summaries run along an axisOptional Reading
Functions like sum(), mean(), max() and min() collapse the table. The axis argument decides the direction:
Which way does it summarise?
| 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 |
df_stats_axis.py
Note
These functions skip NaN by default — a missing value won't break your total.
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.
df_describe.py
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.
df_stats_subset.py
Key Takeaway
Peek with
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. Quick Check
production.sum(axis=1) gives you…
Quick Check
A column has one NaN. What does df['col'].sum() do with it?