head/tail/info/describe
Four quick commands to look at a table before you analyse it.
In this page:
Syntax
df.head(n)
df.tail(n)
df.info()
df.describe()
head/tail/info/describe
head and tail preview rows, info prints column names, non-null counts and dtypes, and describe gives summary statistics for numeric columns. Use include="all" to describe every column. Always run these first on a new dataset.
Note:
info() is the fastest way to spot missing values and wrong dtypes.
Example: head/tail/info/describe
import pandas as pd
df = pd.DataFrame({"a": [1, 2, 3, 4], "b": [10.5, None, 30.5, 40.5]})
print(df.head(2))
df.info()
print(df.describe())
# Output:
# a b
# 0 1 10.5
# 1 2 NaN
# <class 'pandas.core.frame.DataFrame'>
# RangeIndex: 4 entries, 0 to 3
# Data columns (total 2 columns):
# # Column Non-Null Count Dtype
# --- ------ -------------- -----
# 0 a 4 non-null int64
# 1 b 3 non-null float64
# dtypes: float64(1), int64(1)
# memory usage: 196.0 bytes
# a b
# count 4.000000 3.000000
# mean 2.500000 27.166667
# std 1.290994 15.275252
# min 1.000000 10.500000
# 25% 1.750000 20.500000
# 50% 2.500000 30.500000
# 75% 3.250000 35.500000
# max 4.000000 40.500000
Related Topics
Common Mistakes
- Skipping the first look at the data
- Reading describe without checking count
- Forgetting describe ignores text by default
Chapter Summary
- head and tail preview rows
- info shows dtypes and non-nulls
- describe summarizes numbers
- include="all" covers text
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: