Complete Python Solution Code
Since you need to take screenshots of the outputs, here is the complete, sequential code block
designed to be run in a Jupyter Notebook or Google Colab (which gives the cleanest visual
outputs for screenshots).
# ==========================================
# TASK 1: DATASET LOADING (Marks 2)
# ==========================================
import pandas as pd
# Load the dataset into a Pandas DataFrame
url = "[Link]
df = pd.read_csv(url)
# Display the first 10 rows
print("--- Task 1: First 10 Rows of the Dataset ---")
display([Link](10))
# ==========================================
# TASK 2: DATA EXPLORATION (Marks 2)
# ==========================================
print("\n--- Task 2: Data Exploration ---")
# 1. Display the shape of the dataset
print(f"Dataset Shape (Rows, Columns): {[Link]}\n")
# 2. Check data types of all columns
print("Data Types of Columns:")
print([Link])
print("\n")
# 3. Generate summary statistics of numerical features
print("Summary Statistics of Numerical Features:")
display([Link]())
# ==========================================
# TASK 3: DATA CLEANING (Marks 2)
# ==========================================
print("\n--- Task 3: Data Cleaning ---")
# 1. Identify missing values
print("Missing Values Per Column:")
print([Link]().sum())
print("\n")
# 2. Handle missing values appropriately
# Strategy: Impute numerical columns with median, categorical columns with mode
for col in [Link]:
if df[col].dtype == 'object':
df[col] = df[col].fillna(df[col].mode()[0])
else:
df[col] = df[col].fillna(df[col].median())
print("Missing values handled. Remaining missing values:", [Link]().sum().sum())
# 3. Check and remove duplicate records if any
duplicate_count = [Link]().sum()
print(f"Number of duplicate records found: {duplicate_count}")
if duplicate_count > 0:
df = df.drop_duplicates()
print("Duplicate records removed successfully.")
# ==========================================
# TASK 4: FEATURE SELECTION (Marks 2)
# ==========================================
print("\n--- Task 4: Feature Selection ---")
# Identify relevant features for analysis & remove unnecessary columns such as identifiers (e.g.,
Id)
# Note: Check if an 'Id' or 'ID' column exists before dropping to prevent errors
id_columns = [col for col in [Link] if [Link]() in ['id', 'identifier']]
if id_columns:
print(f"Removing unnecessary column(s): {id_columns}")
df = [Link](columns=id_columns)
else:
print("No specific 'Id' column found, or it was already removed.")
print("\nRemaining columns for analysis:")
print([Link]())
# ==========================================
# TASK 5: DATA PREPROCESSING (Marks 2)
# ==========================================
print("\n--- Task 5: Data Preprocessing ---")
# 1. Convert categorical variables into numerical form (One-Hot Encoding or Label Encoding)
# Using pd.get_dummies for safe, explicit machine learning preprocessing
categorical_cols = df.select_dtypes(include=['object']).[Link]()
print(f"Categorical variables to encode: {categorical_cols}")
df = pd.get_dummies(df, columns=categorical_cols, drop_first=True)
# 2. Preparing the dataset for machine learning and display its preview in the output
print("\nFinal Preprocessed Dataset Preview (First 5 rows):")
display([Link]())