0% found this document useful (0 votes)
46 views3 pages

Python Programs for Data Analysis and Visualization

Uploaded by

tarungu20
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views3 pages

Python Programs for Data Analysis and Visualization

Uploaded by

tarungu20
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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)

Sample Output:
Sum of corresponding elements: [11, 22, 33, 44, 55]

Result: The program successfully adds corresponding elements of two lists.

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 = [Link](data)
median_value = [Link](data)
mode_value = [Link](data)

print("Mean:", mean_value)
print("Median:", median_value)
print("Mode:", mode_value.mode[0])

Sample Output:
Mean: 35.0
Median: 35.0
Mode: 20

Result: The program successfully calculates mean, median and mode of the dataset.

Program 3: Display a Line Chart


Aim: To plot a line chart from (2,5) to (9,10).
Program:
import [Link] as plt

x = [2, 3, 5, 7, 9]
y = [5, 7, 6, 8, 10]

[Link](x, y, marker='o', linestyle='-', color='b')


[Link]("x-axis")
[Link]("y-axis")
[Link]("Line Chart")
[Link]()

Sample Output:
A line chart is displayed with given points.

Result: The program successfully displays a line chart using matplotlib.


Program 4: Display a Scatter Chart
Aim: To create a scatter plot using Matplotlib.
Program:
import [Link] as plt

points = [(2,5), (9,10), (8,3), (5,7), (6,10)]


x, y = zip(*points)

[Link](x, y, color='r', marker='o')


[Link]("x-axis")
[Link]("y-axis")
[Link]("Scatter Chart")
[Link]()

Sample Output:
A scatter plot is displayed with the given points.

Result: The program successfully displays a scatter chart using matplotlib.

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("[Link]")
print([Link](10))

Sample Output:
Displays the first 10 rows of the CSV file.

Result: The program successfully reads a CSV file and displays 10 rows.

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("[Link]")
print([Link]())

Sample Output:
Displays column names, non-null counts, and data types.

Result: The program successfully displays the information of the CSV file.

Program 7: Read an Image and Display It


Aim: To read and display an image using OpenCV and Matplotlib.
Program:
import cv2
import [Link] as plt

image = [Link]("[Link]")
image = [Link](image, cv2.COLOR_BGR2RGB)

[Link](image)
[Link]("off")
[Link]("Image Display")
[Link]()

Sample Output:
Displays the image in a window.

Result: The program successfully reads and displays an image.

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 = [Link]("[Link]")
(height, width, channels) = [Link]

print("Image Height:", height)


print("Image Width:", width)
print("Number of Channels:", channels)

Sample Output:
Image Height: 720
Image Width: 1280
Number of Channels: 3

Result: The program successfully identifies the shape of the image.

You might also like