Topics in this subject
Pandas 1 min read Updated 4 Aug 2026

4. Exploring Data

df.head(3) # first 3 rows

df.head(3)        # first 3 rows
df.tail(3)        # last 3 rows
df.sample(5)      # 5 random rows
df.shape          # (rows, cols)
df.columns        # column labels
df.index          # row labels
df.dtypes         # type of each column
df.info()         # dtypes + non-null counts + memory
df.describe()     # summary stats of numeric columns
df.describe(include='all')   # include categoricals
df.memory_usage(deep=True)   # true memory (incl. object strings)

df['city'].value_counts()    # frequency of each value
df['city'].nunique()         # number of unique
df['city'].unique()          # array of unique values
Method Tells you
info() dtypes, non-null counts, memory — your first look
describe() count/mean/std/min/quartiles/max
value_counts() category frequencies (add normalize=True for %)
nunique() cardinality
memory_usage(deep=True) real memory including strings

🚀 Best Practice: Start EDA with df.info() then df.describe(include='all'). value_counts(dropna=False) reveals hidden NaNs.

Interview Question: How to see the distribution of a categorical column? df['col'].value_counts(normalize=True) for proportions.