Thursday, November 27, 2025

✅ πŸ“˜ Advanced (Hard) Level Projects of DataFrame

 

Beginner Level Projects of DataFrame

 Intermediate Level Projects

7️⃣ Project: Stock Market Trend Analysis

Objective: Compare Open, Close prices + Moving Average.

Concepts Used:

  • Time-series indexing

  • Rolling window

  • Multiple line plots

Example Code:

import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv("stocks.csv") # date, open, close df['date'] = pd.to_datetime(df['date']) df.set_index('date', inplace=True) df['MA20'] = df['close'].rolling(20).mean() plt.plot(df.index, df['close'], label='Close Price') plt.plot(df.index, df['MA20'], label='20-Day MA') plt.legend() plt.title("Stock Trend Analysis") plt.show()

8️⃣ Project: Weather Data – Heatmap

Objective: Show temperature of 12 months & 30 days in a heatmap.

Concepts Used: Pivot table, .imshow(), color mapping.

Example Code:

import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv("weather.csv") # columns: month, day, temp pivot = df.pivot('day', 'month', 'temp') plt.imshow(pivot, aspect='auto') plt.colorbar(label='Temperature') plt.title("Monthly Temperature Heatmap") plt.show()

9️⃣ Project: Advanced Sales Dashboard (Bar + Line + Pie)

Objective: Build a mini dashboard using matplotlib subplots.

Concepts Used:

  • Subplots

  • Aggregation

  • Advanced plotting

Example Code:

import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv("store_data.csv") plt.figure(figsize=(12,8)) # 1. Bar – category sales plt.subplot(2,2,1) cat = df.groupby('category')['sales'].sum() plt.bar(cat.index, cat.values) plt.title("Category Sales") # 2. Line – monthly trend plt.subplot(2,2,2) monthly = df.groupby('month')['sales'].sum() plt.plot(monthly.index, monthly.values, marker='o') plt.title("Monthly Sales Trend") # 3. Pie – region split plt.subplot(2,2,3) region = df.groupby('region')['sales'].sum() plt.pie(region.values, labels=region.index, autopct="%1.1f%%") plt.title("Region Sales Share") plt.tight_layout() plt.show()

✅ πŸ“˜ Intermediate Level Projects of Data Frame

 

Beginner Level Projects of DataFrame 

Pandas DataFrame for Beginners

1. Project: COVID-19 Cases Analysis

Objective: Analyze daily cases, 7-day average, and plot graphs.

Concepts Used: CSV reading, rolling average, line plot.

Sample Code:

import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv("covid_data.csv") # columns: date, cases df['7_day_avg'] = df['cases'].rolling(window=7).mean() plt.plot(df['date'], df['cases'], label='Daily Cases') plt.plot(df['date'], df['7_day_avg'], label='7 Day Average') plt.legend() plt.xticks(rotation=45) plt.title("COVID-19 Daily Cases") plt.show()

2.Project: Online Store Sales Analysis

Objective: Compare monthly revenue using bar + line chart.

Concepts Used: Groupby, sum, multiple plots.

Sample Code:

import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv("sales.csv") # columns: month, revenue monthly = df.groupby('month')['revenue'].sum() plt.bar(monthly.index, monthly.values) plt.plot(monthly.index, monthly.values, marker='o') plt.title("Monthly Revenue") plt.xlabel("Month") plt.ylabel("Revenue") plt.show()

3.Project: Movie Ratings Analysis

Objective: Show average movie rating per genre.

Concepts Used: Groupby, sorting, bar plot.

Sample Code:

import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv("movies.csv") # genre, rating genre_rating = df.groupby('genre')['rating'].mean().sort_values() plt.barh(genre_rating.index, genre_rating.values) plt.title("Average Rating by Genre") plt.xlabel("Rating") plt.show()

✅ πŸ“˜ Beginner Level Projects of DataFrame (Easy)

 

Pandas DataFrame

1️⃣ Project: Student Marks Visualization

Objective: Read student marks, calculate total & average, and plot a bar chart.

Concepts Used: DataFrame creation, column operations, bar plot.

Sample Code:

import pandas as pd import matplotlib.pyplot as plt data = { 'Name': ['Amit', 'Riya', 'John'], 'Math': [80, 90, 75], 'Science': [85, 88, 70], 'English': [78, 92, 82] } df = pd.DataFrame(data) df['Total'] = df[['Math', 'Science', 'English']].sum(axis=1) plt.bar(df['Name'], df['Total']) plt.title("Total Marks of Students") plt.xlabel("Students") plt.ylabel("Total Marks") plt.show()

2️⃣ Project: Daily Temperature Line Chart

Objective: Visualize temperature trend over 7 days.

Concepts Used: Line plot, indexing.

Sample Code:

import pandas as pd import matplotlib.pyplot as plt data = { 'Day': ['Mon','Tue','Wed','Thu','Fri','Sat','Sun'], 'Temp': [30, 32, 31, 29, 28, 33, 34] } df = pd.DataFrame(data) plt.plot(df['Day'], df['Temp'], marker='o') plt.title("Daily Temperature") plt.xlabel("Day") plt.ylabel("Temperature (°C)") plt.show()

3️⃣ Project: Product Sales Pie Chart

Objective: Show sales % of products.

Concepts Used: Pie chart, percentage labels.

Sample Code:

import pandas as pd import matplotlib.pyplot as plt data = { 'Product': ['Shoes','Bags','Shirts','Jeans'], 'Sales': [450, 300, 200, 150] } df = pd.DataFrame(data) plt.pie(df['Sales'], labels=df['Product'], autopct='%1.1f%%') plt.title("Product Sales Distribution") plt.show()

πŸ“˜ Pandas DataFrame for Beginners

Pandas DataFrame A DataFrame in Pandas is like a table with rows and columns  similar to an Excel sheet.

It is used for storing and analyzing structured data in Python.


1️⃣ How to Import Pandas

import pandas as pd

2️⃣ Creating a DataFrame

✔ Create DataFrame from a Dictionary

import pandas as pd data = { 'Name': ['Amit', 'Riya', 'John'], 'Age': [22, 25, 28], 'City': ['Delhi', 'Mumbai', 'Pune'] } df = pd.DataFrame(data) print(df)

Output

Name Age City 0 Amit 22 Delhi 1 Riya 25 Mumbai 2 John 28 Pune

3️⃣ Reading Data from a File

CSV File

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

Excel File

df = pd.read_excel("data.xlsx")

4️⃣ Basic Operations on DataFrame

✔ View First & Last Rows

df.head() # first 5 rows df.tail() # last 5 rows

✔ Get Information About Data

df.info() df.describe()

5️⃣ Selecting Data

✔ Selecting One Column

df['Name']

✔ Selecting Multiple Columns

df[['Name', 'City']]

✔ Selecting Rows using index

df.loc[0] # by label df.iloc[0] # by position

6️⃣ Filtering Data

df[df['Age'] > 24]

7️⃣ Adding Columns

df['Age_after_5_years'] = df['Age'] + 5

8️⃣ Removing Columns

df.drop('City', axis=1, inplace=True)

9️⃣ Sorting

df.sort_values(by='Age')

πŸ”Ÿ Handling Missing Values

Find missing values

df.isnull().sum()

Fill missing values

df.fillna(0)

πŸ§ͺ Simple Beginner Project (Mini Project)

Project: Student Marksheet Analysis

Steps:

  1. Create a DataFrame of students with marks.

  2. Calculate total and average.

  3. Find toppers.

  4. Plot results (optional).

Example

import pandas as pd data = { 'Name': ['Amit', 'Riya', 'John'], 'Math': [80, 90, 75], 'Science': [85, 88, 70], 'English': [78, 92, 82] } df = pd.DataFrame(data) df['Total'] = df[['Math', 'Science', 'English']].sum(axis=1) df['Average'] = df['Total'] / 3 print(df)

Wednesday, November 19, 2025

πŸ“Έ Image Processing with Python – Complete Guide

 Image Processing means converting, enhancing, analyzing, or transforming images using computational techniques.

Python is widely used for image processing because of libraries like:

  • NumPy (fast array operations)

  • PIL/Pillow (basic image manipulation)

  • OpenCV (advanced computer vision)

  • Matplotlib (display images)


⭐ 1. Install Required Libraries

pip install pillow opencv-python numpy matplotlib

⭐ 2. Load and Display an Image

Using PIL

from PIL import Image import matplotlib.pyplot as plt img = Image.open("image.jpg") plt.imshow(img) plt.axis('off')

Using OpenCV

Note: OpenCV loads images in BGR format (not RGB).

import cv2 import matplotlib.pyplot as plt img = cv2.imread("image.jpg") img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) plt.imshow(img_rgb) plt.axis("off")

⭐ 3. Convert Image to Grayscale

Using PIL + NumPy

import numpy as np from PIL import Image img = Image.open("image.jpg") img_arr = np.array(img) gray = np.dot(img_arr[...,:3], [0.299, 0.587, 0.114]) plt.imshow(gray, cmap='gray') plt.axis("off")

What is happening?

  • RGB → turned into a single intensity value

  • Weighted formula gives grayscale


⭐ 4. Resize an Image

Using PIL

resized = img.resize((300, 300)) plt.imshow(resized) plt.axis('off')

Using OpenCV

resized = cv2.resize(img_rgb, (300, 300)) plt.imshow(resized) plt.axis('off')

⭐ 5. Rotate an Image

Using PIL

rotated = img.rotate(45) plt.imshow(rotated) plt.axis('off')

Using OpenCV

(h, w) = img_rgb.shape[:2] matrix = cv2.getRotationMatrix2D((w/2, h/2), 45, 1) rotated = cv2.warpAffine(img_rgb, matrix, (w, h)) plt.imshow(rotated) plt.axis('off')

⭐ 6. Flipping an Image

flip_h = cv2.flip(img_rgb, 1) # horizontal flip_v = cv2.flip(img_rgb, 0) # vertical plt.imshow(flip_h) plt.axis('off')

⭐ 7. Edge Detection (Canny Algorithm)

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) edges = cv2.Canny(gray, 100, 200) plt.imshow(edges, cmap='gray') plt.axis('off')

What it does:

  • Detects borders/edges in the image

  • Used in object detection, OCR, robotics


⭐ 8. Image Thresholding (Black & White)

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) _, thresh = cv2.threshold(gray, 120, 255, cv2.THRESH_BINARY) plt.imshow(thresh, cmap='gray') plt.axis('off')

⭐ 9. Blurring / Smoothing

Gaussian Blur

blur = cv2.GaussianBlur(img_rgb, (15, 15), 0) plt.imshow(blur) plt.axis('off')

Mean Blur

blur = cv2.blur(img_rgb, (10, 10)) plt.imshow(blur) plt.axis('off')

⭐ 10. Image Histogram (Intensity Distribution)

import cv2 import matplotlib.pyplot as plt gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) plt.hist(gray.ravel(), 256) plt.show()

⭐ 11. Morphological Operations

Used in noise removal, object extraction.

Erosion

kernel = np.ones((5,5), np.uint8) eroded = cv2.erode(gray, kernel, iterations=1)

Dilation

dilated = cv2.dilate(gray, kernel, iterations=1)

⭐ 12. Image Masking (Focus on a Region)

mask = np.zeros(img_rgb.shape[:2], dtype="uint8") mask[100:300, 100:300] = 255 masked = cv2.bitwise_and(img_rgb, img_rgb, mask=mask) plt.imshow(masked) plt.axis('off')

⭐ 13. Image Contour Detection (Detect Shapes)

gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) _, thresh = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY) contours, _ = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE) cv2.drawContours(img_rgb, contours, -1, (255, 0, 0), 2) plt.imshow(img_rgb) plt.axis('off')

⭐ 14. Face Detection Using Haarcascade

face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(gray, 1.3, 5) for (x,y,w,h) in faces: cv2.rectangle(img_rgb,(x,y),(x+w,y+h),(255,0,0),2) plt.imshow(img_rgb) plt.axis('off')

⭐ 15. Image Segmentation using K-Means

pixels = img_rgb.reshape((-1, 3)) pixels = np.float32(pixels) k = 4 criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 100, 0.2) _, labels, centers = cv2.kmeans(pixels, k, None, criteria, 10, cv2.KMEANS_RANDOM_CENTERS) centers = np.uint8(centers) segmented = centers[labels.flatten()] segmented = segmented.reshape(img_rgb.shape) plt.imshow(segmented) plt.axis('off')

✅ ADVANCED LEVEL NumPy Projects

 

1. Movie Recommendation (Cosine Similarity)

Description:
Build a basic recommendation system using cosine similarity between movie ratings.

Concepts: Dot product, vector norms

Code:

import numpy as np user1 = np.array([4, 3, 5, 0, 2]) user2 = np.array([5, 3, 4, 2, 1]) cos_sim = np.dot(user1, user2) / (np.linalg.norm(user1) * np.linalg.norm(user2)) print("Similarity Score:", cos_sim)

2. Predict House Price (Simple Linear Regression from Scratch)

Description:
Use NumPy to implement linear regression manually (no sklearn).

Concepts: Mean, covariance, slope, intercept

Code:

import numpy as np # Dataset area = np.array([800, 1000, 1200, 1500, 1800]) price = np.array([120, 150, 180, 220, 260]) # slope (m) m = np.cov(area, price)[0,1] / np.var(area) # intercept (c) c = price.mean() - m * area.mean() print("Slope:", m) print("Intercept:", c) # Predict price for 1600 sq ft pred = m * 1600 + c print("Predicted Price:", pred)

3. COVID-19 Daily Cases Simulation & Plot

Description:
Simulate daily cases using random integers and plot the trend.

Concepts: random, matplotlib, cumulative sum

Code:

import numpy as np import matplotlib.pyplot as plt cases = np.random.randint(50, 500, 30) total_cases = np.cumsum(cases) plt.plot(total_cases) plt.title("COVID Cases Simulation") plt.xlabel("Days") plt.ylabel("Total Cases") plt.show()

✅ 4. Sudoku Validator Using NumPy

Description:
Check if a Sudoku solution is valid using row/column uniqueness.

Concepts: array slicing, unique()

Code:

import numpy as np board = np.array([ [5,3,4,6,7,8,9,1,2], [6,7,2,1,9,5,3,4,8], [1,9,8,3,4,2,5,6,7], [8,5,9,7,6,1,4,2,3], [4,2,6,8,5,3,7,9,1], [7,1,3,9,2,4,8,5,6], [9,6,1,5,3,7,2,8,4], [2,8,7,4,1,9,6,3,5], [3,4,5,2,8,6,1,7,9] ]) def is_valid(board): for i in range(9): if len(np.unique(board[i])) != 9 or len(np.unique(board[:,i])) != 9: return False return True print("Valid Sudoku:", is_valid(board))

✅ INTERMEDIATE LEVEL NumPy Projects

 Link for :

ADVANCED LEVEL NumPy Projects

1.Weather Data Simulation

Description:
Simulate 365 days of temperature data using normal distribution and analyze it.

Concepts: Random, mean, std

Code:

import numpy as np temps = np.random.normal(30, 5, 365) print("Average Temp:", temps.mean()) print("Max Temp:", temps.max()) print("Min Temp:", temps.min())

Output::--
Average Temp: 30.00229934869199 Max Temp: 44.1532483791829 Min Temp: 12.372748506925145

2. Image Processing (Convert Image to Grayscale)

Description:
Use NumPy to convert an image to grayscale (conceptual level).

Concepts: Array manipulation

Code:

import numpy as np from PIL import Image img = Image.open("sample.jpg") img_arr = np.array(img) gray = np.dot(img_arr[...,:3], [0.2989, 0.5870, 0.1140]) print(gray)

Output::--
[[242.763 242.763 242.763 ... 254.9745 254.9745 254.9745] [242.763 242.763 242.763 ... 254.9745 254.9745 254.9745] [242.763 242.763 242.763 ... 254.9745 254.9745 254.9745] ... [ 0. 61.5638 204.7217 ... 254.9745 254.9745 254.9745] [ 0. 61.5638 204.7217 ... 254.9745 254.9745 254.9745] [ 0. 61.5638 204.7217 ... 254.9745 254.9745 254.9745]]

3. Matrix Calculator (Add, Multiply, Inverse)

Description:
Perform matrix operations like addition, multiplication, determinant, and inverse.

Concepts: linalg (linear algebra)

Code:

import numpy as np A = np.array([[2, 3], [1, 4]]) B = np.array([[1, 0], [2, 5]]) print("Addition:\n", A + B) print("Multiplication:\n", A.dot(B)) print("Determinant of A:", np.linalg.det(A)) print("Inverse of A:\n", np.linalg.inv(A))

Output::-
Addition: [[3 3] [3 9]] Multiplication: [[ 8 15] [ 9 20]] Determinant of A: 5.000000000000001 Inverse of A: [[ 0.8 -0.6] [-0.2 0.4]]

✅ BEGINNER LEVEL NumPy Projects

 

INTERMEDIATE LEVEL NumPy Projects


1. Temperature Converter Using NumPy

Description:
Convert a list of Celsius temperatures into Fahrenheit using vectorized operations.

Concepts used: Vectorization, arrays

Code:

import numpy as np celsius = np.array([0, 10, 20, 30, 40]) fahrenheit = (celsius * 9/5) + 32 print("Fahrenheit:", fahrenheit)
Output::-- Fahrenheit: [ 32. 50. 68. 86. 104.]

2. Student Marks Analysis

Description:
Calculate total, average, highest, and lowest marks using NumPy functions.

Concepts: Aggregations (sum, max, min, mean)

Code:

import numpy as np marks = np.array([78, 90, 66, 82, 95]) print("Total:", marks.sum()) print("Average:", marks.mean()) print("Highest:", marks.max()) print("Lowest:", marks.min())

Output::--
Total: 411
Average: 82.2 Highest: 95 Lowest: 66

3. Random Password Generator

Description:
Generate a random numeric password using NumPy's random module.

Concepts: random.randint()

Code:

import numpy as np password = np.random.randint(0, 9, 6) print("Generated Password:", ''.join(map(str, password)))

Output::--Generated Password: 007622

✅ NumPy in Python – From Beginner to Hard Level (With Programs)

 

BEGINNER LEVEL NumPy Projects

1. Introduction to NumPy

NumPy (Numerical Python) is a Python library used for:

  • Fast numerical computation

  • Working with arrays (faster than Python lists)

  • Scientific computing

  • Machine learning & data analysis

Installation

pip install numpy

Import

import numpy as np

2. NumPy Array Basics

2.1 Creating Arrays

From Python list

import numpy as np arr = np.array([1, 2, 3, 4]) print(arr)

2D Array

arr2 = np.array([[1, 2, 3], [4, 5, 6]]) print(arr2)

Check Data Type

print(arr.dtype)

2.2 Array Built-in Functions

Zeros, Ones, Full

np.zeros(5) np.ones((2,3)) np.full((3,3), 7)

Arange & Linspace

np.arange(1, 10, 2) # step size np.linspace(1, 5, 10) # 10 equal points

3. Array Indexing & Slicing

Indexing

arr = np.array([10, 20, 30, 40]) print(arr[2]) # 30

Slicing

print(arr[1:3]) print(arr[:3]) print(arr[::-1]) # reverse

2D Array Indexing

arr = np.array([[1, 2, 3], [4, 5, 6]]) print(arr[1, 2]) # 6 print(arr[:, 1]) # column 1

4. Array Math Operations

Element-wise operations

arr = np.array([1, 2, 3]) print(arr + 5) print(arr * 2) print(arr ** 2)

Array to array

a = np.array([1, 2, 3]) b = np.array([4, 5, 6]) print(a + b) print(a * b)

5. Aggregate Functions

arr = np.array([2, 5, 8, 10]) arr.sum() arr.max() arr.min() arr.mean() arr.std() # standard deviation arr.var() # variance

6. Reshaping Arrays

Reshape

arr = np.arange(12) new_arr = arr.reshape((3,4)) print(new_arr)

Flatten

arr.flatten()

7. Stacking Arrays

Vertical Stack

a = np.array([1, 2, 3]) b = np.array([4, 5, 6]) np.vstack((a, b))

Horizontal Stack

np.hstack((a, b))

8. NumPy Broadcasting

Broadcasting allows operations on arrays of different shapes.

Example

arr = np.array([1,2,3]) print(arr + 10)

2D + 1D example

a = np.array([[1,2,3], [4,5,6]]) b = np.array([10, 20, 30]) print(a + b)

9. Boolean Indexing

Filter

arr = np.array([10, 21, 32, 43, 54]) print(arr[arr > 30])

10. NumPy Random Module

Random number

np.random.rand(3) # 1D np.random.rand(3, 3) # 2D

Random integers

np.random.randint(1, 10, 5)

Random normal distribution

np.random.randn(3, 3)

11. Advanced NumPy

11.1 Vectorization (Speed Improvement)

Without NumPy (slow)

lst = [1, 2, 3, 4] result = [x * 2 for x in lst]

With NumPy (fast)

arr = np.array([1,2,3,4]) print(arr * 2)

11.2 Matrix Operations

Matrix multiplication

a = np.array([[1, 2], [3, 4]]) b = np.array([[5, 6], [7, 8]]) print(a.dot(b))

11.3 Statistical Operations

Correlation

arr = np.array([1,2,3,4,5]) print(np.corrcoef(arr))

Percentile

np.percentile([10,20,30,40], 50)

11.4 NumPy with Files

Save array to file

np.save("data.npy", arr)

Load array

arr = np.load("data.npy")

12. Hard Level – Practical Programs

12.1 Matrix Inverse, Determinant

arr = np.array([[2, 1], [5, 3]]) print(np.linalg.det(arr)) print(np.linalg.inv(arr))

12.2 Eigenvalues & Eigenvectors

A = np.array([[4, 2], [1, 3]]) values, vectors = np.linalg.eig(A) print(values) print(vectors)

12.3 Solve Linear Equation

Solve:
2x + 3y = 8
3x + 4y = 11

A = np.array([[2,3],[3,4]]) B = np.array([8,11]) solution = np.linalg.solve(A, B) print(solution)

12.4 Convolution (Image processing concept)

signal = np.array([1,2,3]) kernel = np.array([0,1]) print(np.convolve(signal, kernel))

12.5 NumPy + Matplotlib Plot

(asked earlier also)

import numpy as np import matplotlib.pyplot as plt x = np.linspace(0, 10, 100) y = np.sin(x) plt.plot(x, y) plt.title("Sine Wave") plt.show()

Python Viva Questions

  Basic Python Viva Questions 1. What is Python? Python is a high-level, interpreted, and object-oriented programming language used for w...