Inspecting Data

Python · Pandas Basics

Theory

Before cleaning or analysing, look at what you loaded. df.head(n) and df.tail(n) show the first and last rows, df.shape gives (rows, columns), df.dtypes lists each column's type and df.info() combines types, non-null counts and memory use in one report. df.describe() summarises numeric columns (count, mean, std, min, quartiles, max); describe(include='object') does the same for text columns.

For categories, df['city'].value_counts() counts how often each value appears, sorted from most to least common; normalize=True gives proportions and dropna=False includes missing values. df['city'].nunique() counts distinct values and df['city'].unique() lists them. df.isna().sum() counts missing values per column. Together these quickly reveal wrong types, typos, unexpected nulls and outliers.

Why we use it

Most data bugs are visible in the first minute of inspection: a numeric column read as text, a city spelled two ways, a column that is half empty. Inspecting first saves you from analysing broken data.

When to use it

Run these right after loading any dataset and again after each major transformation. value_counts and nunique are also the quickest way to check if a column is a sensible key or category before a join or groupby.

How it works

  1. New DataFrame loaded
  2. head() / tail(): eyeball sample rows
  3. shape, dtypes, info(): size, types, non-null counts
  4. describe(): ranges and averages of numeric columns
  5. value_counts() / nunique(): check categories and keys
  6. Anything odd (wrong type, nulls, typos)? Yes: Note it for cleaning. No: Move on to analysis.
  7. Know your data

Syntax

df.head(); df.tail(); df.shape; df.dtypes; df.info()
df.describe()
df['col'].value_counts(); df['col'].nunique()

Example

print(df.shape)
df.info()
print(df['city'].value_counts())

Key points

Python topics

Getting Started

Variables & Data Types

Operators

Strings

Lists

Tuples

Sets

Dictionaries

Control Flow

Loops

Functions & OOP

Working with Data

Tooling & Errors

File Handling

Exception Handling

NumPy Library

Pandas Basics

Data Cleaning

Combining DataFrames (SQL Joins & Unions)

GroupBy & SQL-Style Analytics

Reshaping & Workflow

Data Visualization

Machine Learning (Scikit-Learn)

Advanced Python & AI

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Python for Data Analysts

From basics to business insights — the complete step-by-step Python roadmap. Click any topic in the sidebar to open it right here.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice Python Online 141 Python questions for data analysts — strings, records, dates, statistics and regex — with hidden tests and instant verdicts. Start practising →
Section {{ sec.num }}

{{ sec.label }}

Python  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs real Python 3.12 in your browser (first run loads the engine)
{{ liveOutput }}
{{ liveError }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic