Python for Data Analysis
Analyse and visualise data using Python's powerful libraries - Pandas, NumPy, and Matplotlib.
0 of 10 concepts completed (0%)
What You'll Learn
Tutorial Contents
1.Loading & Exploring Data
import pandas as pddf = pd.read_csv("data.csv") df = pd.read_csv("data.csv", parse_dates=["created_at"], index_col="id") df = pd.read_parquet("data.parquet") # faster for large files
# Always run these first print(df.shape) print(df.dtypes) df.info() df.describe() df.head(10) df.sample(5)
# Missing data analysis print(df.isnull().sum()) print(df.isnull().mean() * 100) # % missing per column
# Unique values print(df["status"].value_counts()) print(df["category"].nunique()) ```
2.Cleaning & Transforming Data
# Handle missing values
df["age"].fillna(df["age"].median(), inplace=True)
df.dropna(subset=["email"], inplace=True)# Type conversions df["price"] = pd.to_numeric(df["price"], errors="coerce") # NaN on failure df["date"] = pd.to_datetime(df["date"]) df["category"] = df["category"].astype("category")
# String operations df["name"] = df["name"].str.strip().str.title() df["email"] = df["email"].str.lower()
# Extract date parts df["year"] = df["date"].dt.year df["month"] = df["date"].dt.month df["day_of_week"] = df["date"].dt.day_name()
# Derived features df["revenue"] = df["price"] * df["quantity"] df["discount_pct"] = ((df["original_price"] - df["price"]) / df["original_price"] * 100).round(1)
# Binning df["age_group"] = pd.cut(df["age"], bins=[0, 18, 35, 55, 100], labels=["teen", "young", "middle", "senior"])
# Remove duplicates df.drop_duplicates(subset=["email"], keep="first", inplace=True) ```
3.Aggregation & Visualisation
import matplotlib.pyplot as plt# GroupBy aggregation summary = df.groupby("category").agg( count = ("id", "count"), avg_price = ("price", "mean"), total_rev = ("revenue", "sum") ).round(2).reset_index()
# Pivot table pivot = df.pivot_table( values="revenue", index="region", columns="quarter", aggfunc="sum", fill_value=0, margins=True )
# Multi-panel figure sns.set_theme(style="whitegrid") fig, axes = plt.subplots(2, 2, figsize=(14, 10)) fig.suptitle("Sales Dashboard", fontsize=16, fontweight="bold")
# Bar chart monthly = df.groupby("month")["revenue"].sum() axes[0,0].bar(monthly.index, monthly.values, color="#6200ee", alpha=0.8) axes[0,0].set_title("Monthly Revenue")
# Correlation heatmap corr = df[["price","quantity","revenue"]].corr() sns.heatmap(corr, annot=True, fmt=".2f", cmap="coolwarm", ax=axes[1,1])
plt.tight_layout() plt.savefig("dashboard.png", dpi=150, bbox_inches="tight") ```
Code Example
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# Load data
df = pd.read_csv("sales.csv")
# Explore
print(df.head())
print(df.describe())
# Clean
df.dropna(inplace=True)
df["date"] = pd.to_datetime(df["date"])
# Aggregate
monthly = df.groupby(df["date"].dt.month)["revenue"].sum()
# Visualise
monthly.plot(kind="bar", title="Monthly Revenue")
plt.xlabel("Month")
plt.ylabel("Revenue ($)")
plt.tight_layout()
plt.savefig("revenue.png")Pro Tips
- 1Always call df.describe() and df.info() first to understand your data before transforming it.
- 2Use df.copy() when creating a derived dataframe you plan to modify prevents the SettingWithCopyWarning and silent bugs.
- 3Vectorized operations are 10-1000x faster than loops. If you're writing 'for row in df.iterrows()', there's almost always a vectorized alternative.
- 4Matplotlib's object-oriented interface (fig, ax = plt.subplots()) is required for subplots and gives you much more control.
Topics Covered
Continue Learning
Explore the official documentation and deepen your knowledge with real-world practice.
Explore the Full Portfolio
This is the complete portfolio of Sufi Khan Sulaiman, a technology leader specialising in B2B commerce and digital automation. Start from the Home page for the overview, then move through two decades of career experience across FLIR Systems, Lorex Technology, and 1c Platform, and the full catalogue of project case studies spanning headless commerce migrations, AI recommendation engines, and multi-channel fulfilment systems.
The skills and certifications page maps the technical and leadership capabilities behind the work, while the articles and the knowledge base break down the thinking into actionable frameworks. For hands-on learning, the tutorials and applications sections cover practical builds from front-end fundamentals to full-stack web apps.
For consulting engagement, the expertise page outlines service offerings, the ecommerce hub covers platform architecture and automation strategy, and the ecommerce guide (PDF) is a downloadable 55-page field manual. When you are ready to talk, the contact page is the direct line.