🐼 Python Pandas examples

Python Pandas examples

Copy-ready pandas snippets and data cleaning workflows for CSV files, Excel reports, dashboards, analysis notebooks and repeatable reporting tasks.

62 pandas pages310 practical examplesCopy-ready code

💡 Ideas for You

Learning resources for Python Pandas, data cleaning and analysis.

4 useful links

Some links in this section may be affiliate links. Choose only what is useful for your own work.

Browse Python Pandas examples

Use the search box or filter chips to find pandas examples by workflow. Results update in place without jumping or scrolling.

Basics

read_csv Examples

Load CSV files into DataFrames, handle delimiters, select columns, parse dates and clean common import issues.

Basics

read_excel Examples

Load Excel worksheets, choose sheets, skip header rows, read specific columns and combine sheets.

Basics

DataFrame Create Examples

Create DataFrames from dictionaries, lists, records and simple business tables.

Basics

Select Columns Examples

Select one column, multiple columns, ranges of columns and columns by pattern.

Basics

Rename Columns Examples

Rename columns, standardize messy headers and prepare imported files for analysis.

Basics

sort_values Examples

Sort rows by revenue, dates, multiple columns and custom business priorities.

Basics

head tail sample Examples

Preview data with head, tail, sample and quick checks before cleaning or analysis.

Filtering

Filter Rows Examples

Filter rows by conditions, dates, text, missing values and multiple business rules.

Filtering

query Examples

Use DataFrame.query for readable filters with numbers, text, dates and variables.

Filtering

isin Examples

Filter rows where values match a list of regions, products, statuses or IDs.

Filtering

between Examples

Filter numeric and date ranges such as revenue bands, age ranges and reporting windows.

Filtering

loc and iloc Examples

Select rows and columns by labels or positions using loc and iloc.

Filtering

Drop Rows Examples

Drop unwanted rows by index, condition, blank values and business rules.

Cleaning

Missing Values Examples

Find, fill, drop and report missing values in columns and business datasets.

Cleaning

fillna Examples

Fill missing values with constants, averages, forward fill and group-based values.

Cleaning

dropna Examples

Remove rows or columns with missing values while protecting important records.

Cleaning

drop_duplicates Examples

Remove duplicate customers, emails, products and records safely.

Cleaning

replace Examples

Replace values, standardize statuses, fix spelling and clean imported codes.

Cleaning

astype Examples

Convert columns to strings, integers, floats, categories and booleans.

Cleaning

to_numeric Examples

Convert messy number text to numeric values and handle invalid entries.

Cleaning

Text Cleaning Examples

Clean names, codes and imported text using strip, lower, upper and replace.

Cleaning

str.contains Examples

Filter text by words, phrases, patterns and case-insensitive matches.

Cleaning

extract Regex Examples

Extract IDs, dates, codes and parts of text into new columns.

Dates & Times

to_datetime Examples

Convert text dates to datetime and handle mixed date formats.

Dates & Times

Date Filter Examples

Filter records by date range, month, year, week and recent periods.

Dates & Times

Date Parts Examples

Create year, month, quarter, weekday and month name columns.

Dates & Times

resample Examples

Summarize time series by day, week, month, quarter and year.

Dates & Times

Date Difference Examples

Calculate days between dates, customer age, delivery time and overdue records.

Grouping

groupby Examples

Group sales, customers and operations data by category, region, date or status.

Grouping

agg Examples

Create multiple summaries such as sum, mean, count and max in one table.

Grouping

value_counts Examples

Count categories, statuses, product types and survey answers.

Grouping

pivot_table Examples

Build Excel-like pivot tables with rows, columns, values and totals.

Grouping

crosstab Examples

Create cross-tab summaries for categories, segments and survey results.

Grouping

Rank Examples

Rank products, customers or regions by sales, margin or score.

Grouping

Rolling Window Examples

Calculate rolling averages, rolling sums and moving metrics over time.

Merge & Join

merge Examples

Join sales, customers, products and lookup tables with keys.

Merge & Join

Left Join Examples

Keep all records from the left table and bring matching lookup fields.

Merge & Join

concat Examples

Stack files, append monthly reports and combine same-structure tables.

Merge & Join

Combine CSV Files Examples

Combine many CSV files from a folder into one DataFrame.

Merge & Join

map Examples

Map codes to labels, replace IDs with names and create simple lookups.

Merge & Join

Join Validation Examples

Check unmatched rows, duplicated keys and join quality after merging data.

Reshaping

melt Examples

Unpivot wide tables into long format for charts and analysis.

Reshaping

pivot Examples

Turn long data into wide columns for reports and exports.

Reshaping

stack and unstack Examples

Reshape MultiIndex data between long and wide formats.

Reshaping

explode Examples

Split list-like values into multiple rows for tags, products or skills.

Reshaping

Split Column Examples

Split full names, codes and combined fields into separate columns.

Reshaping

Wide to Long Examples

Convert spreadsheets with repeated period columns into tidy data.

Exporting

to_csv Examples

Export cleaned DataFrames to CSV with selected columns and formatting choices.

Exporting

to_excel Examples

Export reports to Excel sheets, multiple tabs and formatted workbook outputs.

Exporting

ExcelWriter Examples

Write multiple DataFrames to different Excel sheets in one workbook.

Exporting

to_json Examples

Export records to JSON for APIs, apps and structured files.

Exporting

Report Formatting Examples

Create readable exports with sorted columns, rounded values and renamed headers.

Workflows

Sales Summary Workflow Examples

Clean sales data, calculate KPIs and export a monthly summary.

Workflows

Customer Analysis Workflow Examples

Analyze customers by segment, spend, order count and retention signals.

Workflows

Inventory Workflow Examples

Flag low stock, summarize categories and prepare reorder lists.

Workflows

Expense Cleaning Workflow Examples

Clean bank or expense exports, categorize transactions and summarize spend.

Workflows

Dashboard Prep Workflow Examples

Prepare tidy tables for dashboards in Excel, Power BI or web apps.

Workflows

Data Quality Checks Examples

Check blanks, duplicates, invalid values and unexpected categories before reporting.

Workflows

Monthly Report Workflow Examples

Combine files, clean columns, summarize results and export a monthly report.

Workflows

Content Calendar Workflow Examples

Clean content calendars, track status and summarize workload by channel.

Workflows

Survey Analysis Workflow Examples

Clean survey responses, summarize answers and prepare charts.

Workflows

Log Analysis Workflow Examples

Parse logs, count events, find errors and summarize activity over time.