Program 1: Add Elements of Two Lists
Aim: To write a Python program that adds the corresponding elements of two lists.
Program:
list1 = [1, 2, 3, 4, 5]
list2 = [10, 20, 30, 40, 50]
sum_list = []
for i in range(len(list1)):
sum_list.append(list1[i] + list2[i])
print("Sum of corresponding elements:", sum_list)
Program 2: Calculate Mean, Median and Mode using NumPy
Aim: To calculate the mean, median and mode of a dataset using NumPy and SciPy.
Program:
import numpy as np
from scipy import stats
data = [10, 20, 20, 30, 40, 50, 50, 60]
mean_value = np.mean(data)
median_value = np.median(data)
mode_value = stats.mode(data)
print("Mean:", mean_value)
print("Median:", median_value)
print("Mode:", mode_value.mode[0])
Program 3: Display a Line Chart
Aim: To plot a line chart from (2,5) to (9,10).
Program:
import matplotlib.pyplot as plt
x = [2, 3, 5, 7, 9]
y = [5, 7, 6, 8, 10]
plt.plot(x, y, marker='o', linestyle='-', color='b')
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.title("Line Chart")
plt.show()
Program 4: Display a Scatter Chart
Aim: To create a scatter plot using Matplotlib.
Program:
import matplotlib.pyplot as plt
points = [(2,5), (9,10), (8,3), (5,7), (6,10)]
x, y = zip(*points)
plt.scatter(x, y, color='r', marker='o')
plt.xlabel("x-axis")
plt.ylabel("y-axis")
plt.title("Scatter Chart")
plt.show()
Program 5: Read a CSV File and Display 10 Rows
Aim: To read a CSV file and display the first 10 rows using Pandas.
Program:
import pandas as pd
df = pd.read_csv("data.csv")
print(df.head(10))
Program 6: Read a CSV File and Display Its Information
Aim: To read a CSV file and display its structure and details using Pandas.
Program:
import pandas as pd
df = pd.read_csv("data.csv")
print(df.info())
Program 7: Read an Image and Display It
Aim: To read and display an image using OpenCV and Matplotlib.
Program:
import cv2
import matplotlib.pyplot as plt
image = cv2.imread("image.jpg")
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
plt.imshow(image)
plt.axis("off")
plt.title("Image Display")
plt.show()
Program 8: Read an Image and Identify Its Shape
Aim: To read an image and determine its height, width, and number of channels.
Program:
import cv2
image = cv2.imread("image.jpg")
(height, width, channels) = image.shape
print("Image Height:", height)
print("Image Width:", width)
print("Number of Channels:", channels)