Introduction to Python libraries — NumPy, Pandas, Matplotlib, Scikit-learn & Bokeh — and six core visualizations, applied to a real Cricket Matches dataset. Every chart below draws itself, the way Matplotlib renders it.
Five libraries do the heavy lifting in almost every data-science task. Think of them as a cricket squad — each plays a specialist role.
# one-time setup
pip install numpy pandas matplotlib scikit-learn bokeh
Each visualization answers a different shape of question. Hover or scroll — every mini-chart animates as it enters view.
Compares a value across categories. Best for "which team has the most ___?"
Shows parts of a whole — proportion of total wins per team.
Buckets a continuous variable to reveal its spread and skew.
Tracks a value through time — trend, growth, seasonality.
Reveals correlation between two numeric variables.
Median, quartiles & outliers in one compact summary.
The complete, runnable lab code. Copy each block into a Jupyter / Colab cell. Column names follow the Kaggle ODI match-info CSV; adjust to your file if needed.
# Experiment 1 — Libraries & Visualization on Cricket data
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
# Load the dataset (download the CSV from Kaggle first)
df = pd.read_csv("ODI_Match_info.csv")
# Quick exploration
print(df.head()) # first 5 rows
print(df.shape) # (rows, columns)
print(df.info()) # dtypes & nulls
print(df.describe()) # summary statistics
# Q1: Which country played the most matches?
teams = pd.concat([df["team1"], df["team2"]])
played = teams.value_counts()
print("Most matches:", played.idxmax(), played.max())
played.head(8).plot(kind="bar", color="#1d9e75")
plt.title("Matches Played by Each Country")
plt.xlabel("Country"); plt.ylabel("Matches")
plt.tight_layout(); plt.show()
# Q2: Top 3 countries who won the most matches
wins = df["winner"].value_counts()
top3 = wins.head(3)
print(top3)
plt.pie(top3, labels=top3.index, autopct="%1.1f%%",
colors=["#e0b15e", "#1d9e75", "#e23a2e"])
plt.title("Top 3 Winning Countries"); plt.show()
# Q3: Country that played the most matches at home
# (match the venue city/country to the team's home country)
home = df[df["city_country"] == df["team1"]]
print(home["team1"].value_counts().idxmax())
# Q4: Performance of Sri Lanka
sl = df[(df["team1"]=="Sri Lanka") | (df["team2"]=="Sri Lanka")]
sl_wins = sl[sl["winner"]=="Sri Lanka"]
win_pct = len(sl_wins) / len(sl) * 100
print(f"Sri Lanka win %: {win_pct:.1f}")
# Q5: Team that toured the most foreign countries
away = df[df["city_country"] != df["team2"]]
tours = away.groupby("team2")["city_country"].nunique()
print("Most foreign tours:", tours.idxmax())
# Q6: Month in which most matches are played
df["date"] = pd.to_datetime(df["date"])
df["month"] = df["date"].dt.month_name()
by_month = df["month"].value_counts()
by_month.plot(kind="line", marker="o", color="#e23a2e")
plt.title("Matches by Month"); plt.show()
The six questions from the lab sheet. Each uses representative sample numbers so the chart renders here; run the code on the real CSV for exact figures. Press replay on any chart to watch it draw again.
team1 and team2, India tops the chart — the tallest bar. A bar graph is ideal because we compare one number (match count) across teams.df["winner"].value_counts().head(3) gives the leaders. In our sample: Australia → India → England. A pie chart shows how the three biggest winners split the total.
nunique()). India recorded the widest travel footprint in the sample.date to datetime, extract the month, and count. Activity peaks in the cooler / dry months (Oct–Feb), the heart of the international season.The Python data-science libraries were introduced and all six visualization types — bar, pie, histogram, line, scatter and box plot — were successfully implemented on the Cricket Matches dataset. Every analytical question in the case study was answered through an appropriate chart, demonstrating CO2: creating static, animated and interactive visualizations.