DSA LABData Science Applications
Experiment 01 · CO2

Seeing the Game
Through Data

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.

Course IT416
Outcome CO2
Dataset Cricket / ODI
Plots 6 types

Experiment Scoreboard

LIVE RENDER
0
Chart types
0
Libraries
0
Case questions
0
Animated
01

Lab Manual

Aim
To introduce the core Python data-science libraries (NumPy, Pandas, Matplotlib, Scikit-learn, Bokeh) and to perform data visualization — bar graph, pie chart, box plot, histogram, line plot and scatter plot — on a Cricket Matches dataset, answering analytical questions about teams and matches.
Objectives
  • Load and explore a real-world dataset using Pandas DataFrame.
  • Compute summaries with NumPy and Pandas aggregation.
  • Choose the right chart for each analytical question.
  • Build static and animated visualizations with Matplotlib / Bokeh.
Software
Python 3.x · Jupyter Notebook / Google Colab · libraries installed via pip.
Dataset
Cricket Matches Dataset — Kaggle: kaggle.com/datasets/imdevskp/cricket-data (ODI / T20 match info CSV).
Outcome
CO2 — Creating static, animated, and interactive visualizations using Matplotlib.
02

The Toolkit

Five libraries do the heavy lifting in almost every data-science task. Think of them as a cricket squad — each plays a specialist role.

NumPyFast arrays & math — the "numbers" engine behind everything.
PandasDataFrames: load, clean, group & aggregate tabular data.
MatplotlibThe plotting workhorse — bar, pie, line, scatter, box, histogram.
Scikit-learnMachine-learning models, scaling & metrics (used later).
BokehInteractive, browser-based plots you can zoom & hover.
install.sh
# one-time setup
pip install numpy pandas matplotlib scikit-learn bokeh
03

Six Charts, Six Jobs

Each visualization answers a different shape of question. Hover or scroll — every mini-chart animates as it enters view.

Bar Graph

compare
Matches per team

Compares a value across categories. Best for "which team has the most ___?"

Pie Chart

share
Win share

Shows parts of a whole — proportion of total wins per team.

Histogram

distribution
Innings score distribution

Buckets a continuous variable to reveal its spread and skew.

Line Plot

trend
Matches over the years

Tracks a value through time — trend, growth, seasonality.

Scatter Plot

relationship
Matches vs wins

Reveals correlation between two numeric variables.

Box Plot

5-number
Score spread by team

Median, quartiles & outliers in one compact summary.

04

The Program

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.

1 — load & explore.py
# 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
2 — most matches (bar).py
# 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()
3 — top winners (pie).py
# 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()
4 — home matches & Sri Lanka.py
# 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}")
5 — tours & month (line).py
# 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()
05

Case Study — Answered & Animated

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.

1

Which country played the most matches?

Bar
Total matches played
Answer: Counting appearances across team1 and team2, India tops the chart — the tallest bar. A bar graph is ideal because we compare one number (match count) across teams.
2

Top 3 countries who won the most matches?

Pie
Share of wins (top 3)
Answer: 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.
3

Which country played the most matches at home?

Bar
Home-ground matches
Answer: Filter rows where the venue's country equals the team's country, then count. England hosts the most home fixtures in the sample, reflecting frequent home seasons.
4

How was the performance of Sri Lanka?

Line
Sri Lanka — win % by year
Answer: Win-percentage = (Sri Lanka wins ÷ matches played) × 100. The line shows a strong peak around 2014 followed by a dip — a trend a single number could never reveal.
5

Which team toured the most foreign countries?

Bar
Distinct foreign countries toured
Answer: Group away matches by team and count unique host countries (nunique()). India recorded the widest travel footprint in the sample.
6

In which month are most matches played?

Line
Matches per month
Answer: Convert date to datetime, extract the month, and count. Activity peaks in the cooler / dry months (Oct–Feb), the heart of the international season.
06

Procedure & Result

Steps followed

1 · Import
Load NumPy, Pandas and Matplotlib.
2 · Read
Load the Cricket CSV into a DataFrame.
3 · Explore
Inspect with head, info, describe.
4 · Wrangle
Group, filter and aggregate per question.
5 · Visualize
Plot the right chart for each question.
6 · Interpret
Read the chart and write the conclusion.

Result

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.

Conclusion: The choice of chart matters as much as the data. Bar graphs compare, pies show share, lines reveal trends, scatters expose relationships, histograms show distribution and box plots summarize spread — together they turn a raw CSV into insight.
07

Viva Questions

Difference between a bar graph and a histogram?
A bar graph compares categorical data with gaps between bars; a histogram shows the distribution of a continuous variable using adjacent bins with no gaps.
What is a Pandas DataFrame?
A 2-D, size-mutable, labelled tabular structure — rows and named columns — built on top of NumPy arrays, ideal for cleaning and analysing data.
Why use NumPy instead of Python lists?
NumPy arrays are stored contiguously and vectorized in C, making element-wise math far faster and more memory-efficient than looping over Python lists.
When would you pick a scatter plot?
To study the relationship or correlation between two numeric variables — e.g. matches played vs matches won.
What five numbers does a box plot show?
Minimum, first quartile (Q1), median (Q2), third quartile (Q3) and maximum — with points beyond the whiskers flagged as outliers.
How does Bokeh differ from Matplotlib?
Matplotlib produces static figures; Bokeh renders interactive plots in the browser with pan, zoom, hover and linked tools, exported as HTML/JS.