0% found this document useful (0 votes)
2 views

class 10 Lab Data science (3)

The document contains a series of Python programming tasks, including creating arrays with random integers, calculating statistics for student marks, creating data frames for interview candidates and players, visualizing game ratings and sales data using bar and line charts, and performing image processing tasks like displaying and resizing images. Each task is accompanied by a program code snippet and a note indicating successful execution. Overall, the document serves as a collection of practical exercises for learning Python programming and data visualization.

Uploaded by

rithikaakshara
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

class 10 Lab Data science (3)

The document contains a series of Python programming tasks, including creating arrays with random integers, calculating statistics for student marks, creating data frames for interview candidates and players, visualizing game ratings and sales data using bar and line charts, and performing image processing tasks like displaying and resizing images. Each task is accompanied by a program code snippet and a note indicating successful execution. Overall, the document serves as a collection of practical exercises for learning Python programming and data visualization.

Uploaded by

rithikaakshara
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

8.

Write a python program to create a 3 x 4 array with random integer values less than 10, create a two-
dimensional array of 3 rows and 4 columns with all five values and add those two arrays.

Program:
import numpy as np
a=np.random.randint(10,size=(3,4))
print("Random array ")
print(a)

b=np.full((3,4),5)
print("Full array")
print(b)

#adding two arrays


add=a+b
print("sum of two arrays")
print(add)

output:

Result: Program has been executed successfully

9. write a python program to create a list with student marks and calculate the following using a statistics module.

a. Mean b. Median c. Mode d. Standard deviation e. Variance

Program:
import statistics
#number of students to created
n=int(input("enter number of students "))
L=[]
#creating list
for i in range(n):
print("Enter marks of student ", i+1)
mark=int(input())
L.append(mark)

Ma=statistics.mean(L)
print("mean is:",Ma)

Me=statistics.median(L)
print("Median is:",Me)

Mo=statistics.mode(L)
print("Mode is:",Mo)
sd=statistics.stdev(L)
print("Standard deviation is:",sd)

va=statistics.variance(L)
print("Variace is:",va)

Output:

Result: Program has been executed successfully .

10. Write a program to create a data frame to store data of candidates who appeared

in interviews. The data frame columns are name, score, attempts, and qualify

(Yes/No). Assign rowindex as C001,C002, and so on.

Program:
import pandas as pd
#Creating Dictionary to store data
d={'Name':['Anil','Bhavna','Chirag','Dhara','Giri'],'Score':
[25,20,22,23,21],'Attempts':[1,2,2,1,1],'Qualified':['Yes','No','Yes','Yes','No']}

#Creating a dataframe
df=pd.DataFrame(d,index=['C001','C002','C003','C004','C005'])

print(df)

Output:

Result: Program has been executed successfully .

13. Write a program to create a dataframe named player and store their data in the

columns like team, no. of matches, runs, and average. Assign player name as row
index and display only those players' details whose score is more than 1000.

Program:
import pandas as pd
#Creating Dictionary to store data

d={'Team':['India','South Africa','England','Asutralia'],'Matches':
[25,23,19,17],'Runs':[1120,1087,954,830],'Average':[44.80,47.26,50.21,48.82]}
#Creating a dataframe
player=pd.DataFrame(d,index=['Virat kohli','AB de Villiers','Ben
Stokes','SteveSmith'])

#Displaying data whose runs > 1000


print(player[player['Runs']>1000])

Output:

Result: Program has been executed successfully.

14. Write a program to represent the data on the ratings of mobile games on bar

chart. The sample data is given as:

Pubg, FreeFire, MineCraft, GTA-V, Call of duty, FIFA 22.

The rating for each game is as: 4.5,4.8,4.7,4.6,4.1,4.3.

Program:
#Import package for Matplot Library
import matplotlib.pyplot as plt
#Creating lists for data
games=['Pubg', 'FreeFire', 'MineCraft', 'GTA-V','Call of duty', 'FIFA 22']
rating=[3.5,4.8,4.7,2.6,3.1,1.3]
#Creating bar graph with different bar colours
plt.bar(games,rating,color=['black', 'red', 'green', 'blue', 'yellow'])
#Customizing the bar graph
plt.title("Games Rating 2022")
plt.xlabel('Games')
plt.ylabel('Rating')

plt.show()
Result: Program has been executed successfully .

14. Observe the given data for monthly sales of one of the salesmen for 6 months. Plot them on the line chart.

Month January February March April May June

Sales 2500 2100 1700 3500 3800 4500

Apply the following customizations to the chart:

▪ Give the title for the chart - "Sales Stats"

▪ Use the "Month" label for X-Axis and "Sales" for Y-Axis.

▪ Display legends.

▪ Use dashed lines with the width 5 point.

▪ Use red color for the line.

▪ Use a dot marker with blue edge color and black fill color.

import matplotlib.pyplot as pp
#Prepraing data
mon =['January','February','March','April','May','June']
sales = [2500,2100,1700,3500,3000,3800]
#Creating line chart

pp.plot(mon,sales,label='Sales',color='r',linestyle='solid',marker='o',markerfaceco
lor='b')

#Customizing the chart


pp.title("Sales Report")
pp.xlabel("Months")
pp.ylabel("Sales")
pp.show()
Result: Program has been executed successfully.

15. Write a program to represent the percentage of marks on a pie chart.

Program:
from matplotlib import pyplot as plt
import numpy as np
fig=plt.figure()
x=fig.add_axes([0,0,1,1])

subjects=['Eng','Math','Science','Social','Hindi','Computers']
Marks=[23,45,34,41,13,45]
x.pie(Marks,labels=subjects,autopct='%1.2f%%')
plt.show()

Result: Program has been executed successfully .

16. write a python program to display the image in grayscale.

Program;
import cv2
import matplotlib.pyplot as plt
import numpy as np
img=cv2.imread('C:\\Users\\donbo\\Desktop\\T_logo.png')
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))

plt.title('Bosco logo')
plt.show()

Result: Program has been executed successfully .

17. write a python program to resize the image.

Program:
import cv2
import matplotlib.pyplot as plt
import numpy as np
img=cv2.imread('C:\\Users\\donbo\\Desktop\\T_logo.png')
resiz=cv2.resize(img,(200,300))
plt.imshow(cv2.cvtColor(resiz, cv2.COLOR_BGR2RGB))

plt.title('Resized Bosco logo')


plt.show()
Result: Program has been executed successfully

18. Write a python program to display shape of image, maximum pixel value and minimum pixel value.

Program:
import cv2
import matplotlib.pyplot as plt
import numpy as np
img=cv2.imread('C:\\Users\\donbo\\Desktop\\T_logo.png')
print("pixel value of iamge",img.shape)

print(" min pixel value of iamge",img.min())


print("Max pixel value of iamge",img.max())

Result: Program has been executed successfully

You might also like