Basic DataFrame Inspection
Use head(), tail(), info(), describe(), and shape to quickly understand the content and structure of any DataFrame.
The First Five Steps with Any DataFrame
Whenever you load a new dataset, a systematic inspection sequence saves hours of debugging. The Pandas toolkit for this includes: head() to see the first rows, tail() for the last rows, info() for column types and nulls, describe() for statistics, and shape for dimensions. Running these five checks takes less than a minute and reveals most data quality issues immediately.
import pandas as pd
# Assume df is loaded from a CSV
print(df.shape) # (rows, cols)
df.head() # first 5 rows
df.info() # dtypes + non-null counts
df.describe() # statisticshead() and tail()
df.head(n) returns the first n rows (default 5) as a DataFrame. df.tail(n) returns the last n rows. Together they help you verify that the data was parsed correctly — checking that column names are in the header row, that numeric columns contain numbers, and that date strings were not misinterpreted. They are non-destructive and return new DataFrames.
import pandas as pd
df = pd.DataFrame({'a': range(20), 'b': range(20, 40)})
print(df.head(3))
# a b
# 0 0 20
# 1 1 21
# 2 2 22
print(df.tail(2))
# a b
# 18 18 38
# 19 19 39All lessons in this course
- Creating DataFrames
- Selecting Columns and Rows
- Adding and Dropping Columns
- Basic DataFrame Inspection