head(), tail() & info()
Let me give you the three commands I use most when I first load a dataset. These are your "first look" tools — quick ways to understand what you're dealing with.
head() — Peek at the Top
The `head()` method shows you the first few rows. It's like glancing at the top of a spreadsheet:
import pandas as pd
df = pd.read_csv('data.csv')
print(df.head())
By default, it shows 5 rows. Want more or less? Just pass a number:
print(df.head(10))
tail() — Peek at the Bottom
Same idea, but for the last rows:
print(df.tail())
This is handy for checking if your data ends cleanly or if there are surprises at the bottom.
info() — The Quick Summary
Here is the thing — `info()` is probably the most useful method for getting a bird's eye view of your data:
print(df.info())
It shows you column names, data types, non-null counts, and memory usage. Trust me, always run `info()` first. It tells you instantly if you have missing values or wrong data types.
Try it Yourself →Key Takeaways
- `head()` shows the first 5 rows (or custom amount)
- `tail()` shows the last 5 rows
- `info()` gives a complete overview: types, nulls, memory
- Always run these first when loading new data