SAMANTUS Python for Data Analytics — Complete Training Manual MODULE 17
← Back to Course Index

Python for Data Analytics — Complete Workflows


On This Page

Module 17: Python for Data Analytics — Complete Workflows


17.1  The Complete Data Analytics Workflow

This module brings together everything learned so far — NumPy, Pandas, Matplotlib, and Seaborn — into complete, real, end-to-end analytics workflows, exactly as they're used in the industry.

StageTools UsedGoal
1. Load DataPandas (read_csv/read_excel)Bring raw data into Python
2. Exploredf.info(), describe(), head()Understand structure & quality
3. CleanPandas (dropna, fillna, dedupe)Fix missing values, duplicates
4. TransformPandas, NumPyCreate new columns, aggregate, reshape
5. VisualizeMatplotlib, SeabornReveal patterns and trends
6. Report InsightsWritten summary + chartsCommunicate to stakeholders

17.2  Industry Example 1 — Retail Sales Analysis

Business Question: Which region and product category should get more marketing budget next quarter?

► retail_analysis.py
import pandas as pd

df = pd.read_csv("retail_sales.csv")
df = df.dropna(subset=['revenue'])

region_perf = df.groupby('region')['revenue'].sum().sort_values(ascending=False)
category_perf = df.groupby('category')['revenue'].sum().sort_values(ascending=False)

print("Top Region:", region_perf.index[0])
print("Top Category:", category_perf.index[0])

growth = df.groupby('month')['revenue'].sum().pct_change() * 100
print("Month-over-Month Growth %:\n", growth.round(2))
ℹ Business Insight
The North region and Electronics category together account for over 40% of total revenue — concentrate next quarter's ad budget on this specific combination rather than spreading evenly.

17.3  Industry Example 2 — HR Attrition Analysis

Business Question: Which department has the highest employee attrition, and why?

► hr_attrition.py
import pandas as pd

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

attrition_rate = df.groupby('department')['attrition'].mean() * 100
print("Attrition Rate by Department (%):\n", attrition_rate.round(2))

avg_tenure = df.groupby('department')['years_at_company'].mean()
print("Average Tenure by Department:\n", avg_tenure.round(1))

correlation = df[['satisfaction_score','attrition']].corr()
print(correlation)
ℹ Business Insight
Sales department shows the highest attrition (28%) paired with the lowest average satisfaction score — HR should prioritize retention interviews and compensation review here first.

17.4  Industry Example 3 — Marketing Campaign ROI

Business Question: Which marketing channel gives the best return on ad spend?

► campaign_roi.py
import pandas as pd

df = pd.read_csv("campaign_data.csv")   # columns: channel, spend, revenue

df['roi'] = (df['revenue'] - df['spend']) / df['spend'] * 100

channel_roi = df.groupby('channel')['roi'].mean().sort_values(ascending=False)
print("Average ROI % by Channel:\n", channel_roi.round(2))

best_channel = channel_roi.idxmax()
print("Best performing channel:", best_channel)
✓ Business Insight
Instagram Ads shows the highest average ROI (185%) compared to Google Ads (110%) and Email (95%) — reallocating even 15-20% of budget toward Instagram could meaningfully boost overall returns.

17.5  Building Reusable Analysis Functions

Professional analysts wrap repeated logic into functions, making analysis faster and less error-prone across projects.

► analytics_toolkit.py
import pandas as pd

def quick_summary(df, group_col, value_col):
    """Returns total, average, and count grouped by a category."""
    summary = df.groupby(group_col)[value_col].agg(["sum","mean","count"])
    summary.columns = ['Total', 'Average', 'Count']
    return summary.sort_values("Total", ascending=False)

result = quick_summary(df, "category", "revenue")
print(result)

17.6  Exporting Results for Stakeholders

► Exporting Analysis Results
result.to_csv("category_summary.csv")
result.to_excel("category_summary.xlsx", sheet_name="Summary")

import matplotlib.pyplot as plt
result["Total"].plot(kind="bar", title="Revenue by Category")
plt.savefig("category_chart.png", dpi=150, bbox_inches="tight")
✓ Instructor Tip
Always show students how to export both the data (CSV/Excel) AND the chart (PNG) — this is exactly what gets emailed to managers in a real job.

17.7  Practical Exercises

Basic (5 Questions)

1. Load any dataset and print a full summary (shape, info, describe).

2. Group your dataset by one categorical column and calculate the sum of a numeric column.

3. Create one bar chart summarizing your groupby result.

4. Export a Pandas DataFrame to both a CSV and Excel file.

5. Write a one-function summary that takes a DataFrame and returns basic stats.

Intermediate (5 Questions)

1. Recreate the Retail Sales Analysis example using your own sample dataset.

2. Calculate month-over-month growth % for a revenue column using pct_change().

3. Build a reusable function quick_summary() and test it on 2 different datasets.

4. Create and export a chart alongside your summary CSV, matching filenames.

5. Write 3 business insights based on your own groupby() analysis.

Advanced (5 Questions)

1. Build a complete end-to-end workflow (load → clean → transform → visualize → export) on a dataset of your choice, following all 6 workflow stages.

2. Recreate the HR Attrition or Marketing ROI case study using your own synthetic dataset.

3. Build a toolkit of 3 reusable analytics functions (summary, outlier check, chart export) and use them together on one dataset.

4. Create a 1-page 'Executive Summary' combining 2 charts and 3 written business recommendations.

5. Compare 2 different time periods in a dataset (e.g. Q1 vs Q2) and write a comparative analysis.

17.8  Module Quiz (MCQs)

Q1. What is typically the FIRST stage of any analytics workflow?

Q2. Which function calculates period-over-period growth %?

Q3. Why build reusable functions for analysis?

Q4. Which format is best for sharing results with non-technical managers?

Q5. What should every analytics workflow end with?

ℹ Answer Key
1-b, 2-b, 3-b, 4-b, 5-b

17.9  Module Assignment

Assignment: Complete Business Analytics Workflow

Expected Output: A complete, professional analytics project script from raw data to a stakeholder-ready summary, following the industry-standard workflow.

17.10  Interview Questions — Module 17


17.11  Student Notes Page

Use this space to write down key points, doubts, and your own examples from today's session.