Python for Data Analytics & AutomationLesson 20 of 41
Lesson 20 of 41

Data Inspection, Summary Statistics & Structural Profiling (info, describe, value_counts)

Overview & Learning Objectives

Before executing transformations, data analysts must inspect dataset structure, assess missing values, verify data types, and review distribution percentiles. Pandas provides powerful exploratory inspection utilities (`.info()`, `.describe()`, `.value_counts()`, `.nunique()`) that summarize millions of records in seconds.

  • Inspect column data types, non-null counts, and RAM footprint with `df.info(memory_usage="deep")`.
  • Generate descriptive distribution statistics across numeric and categorical fields using `df.describe()`.
  • Analyze categorical distributions and percentage shares using `df["col"].value_counts(normalize=True)`.
  • Identify cardinality and unique identifier integrity using `df.nunique()`.

Industry Standard

Standard: Analytics teams at Deloitte require running `df.info(memory_usage="deep")` as the first diagnostic step on client datasets to detect string memory bloat and missing values.

Real-World Example: ScoopCraft Dark-Store Health Diagnostics

ScoopCraft runs structural profiling across 50,000 POS order transactions to audit data quality.

Column NameNon-Null CountDtypeUnique ValuesSummary Metric
order_id50,000 (100%)object (str)50,000Unique Primary Key Verified
delivery_city50,000 (100%)category5Top: Bengaluru (42%)
order_total49,850 (99.7%)float321,420Mean: ₹420, Median: ₹350
rider_rating44,200 (88.4%)float3255,800 Missing Ratings (11.6%)

Syntax & Core Code Implementation

import pandas as pd

df = pd.read_csv("zepto_orders.csv")

# 1. Structural inspection & exact memory footprint
df.info(memory_usage="deep")

# 2. Descriptive statistics for both numeric and text columns
summary_stats = df.describe(include="all")

# 3. Categorical distribution & percentage shares
city_counts = df["delivery_city"].value_counts()
city_percentages = df["delivery_city"].value_counts(normalize=True) * 100

# 4. Cardinality & missing checks
unique_per_col = df.nunique()
missing_ratios = df.isna().mean() * 100

Parameters & Arguments Breakdown

  • df.info(memory_usage="deep"): Prints concise summary of DataFrame including index dtype, column dtypes, non-null values, and true deep memory usage.
  • df.describe(include="all"): Generates descriptive statistics (count, unique, top, freq, mean, std, min, 25%, 50%, 75%, max).
  • s.value_counts(normalize=False): Returns Series containing counts of unique values. Setting `normalize=True` returns relative frequencies/percentages.
  • df.nunique(): Counts number of distinct elements per column.

Sample Walkthrough (Q&A)

Question: Why does `df.info()` show a significantly smaller memory footprint unless you specify `memory_usage="deep"`?

Code Pattern: df.info() vs df.info(memory_usage="deep")

Result: Without `"deep"`, Pandas only measures the memory of fixed column pointer arrays, ignoring the actual string contents in memory.

Explanation: In CPython, strings are variable-length heap allocations. `memory_usage="deep"` interrogates the system memory allocator to calculate true string memory.

Common Mistakes & Limitations

  • Assuming `df.describe()` includes categorical string columns by default; you must pass `include="all"` or `include=["object", "category"]`.
  • Relying solely on `mean()` without checking `median()` on skewed business metrics like order revenue and executive salaries.

Keyboard Shortcuts (Jupyter & VS Code)

ActionWindowsMac
Quick Top 5 Rows Previewdf.head()df.head()
Quick Bottom 5 Rows Previewdf.tail()df.tail()

Pro Tips & Modern Best Practices

  • Use `ydata-profiling` (formerly pandas-profiling) to generate comprehensive HTML exploratory audit reports with correlation charts.
  • Use `skimpy` in terminal for lightweight, terminal-based colored summary distributions.
Data Inspection, Summary Statistics & Structural | DataCliq