class 10 Lab Data science (3)
class 10 Lab Data science (3)
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)
output:
9. write a python program to create a list with student marks and calculate the following using a statistics module.
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:
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
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:
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'])
Output:
14. Write a program to represent the data on the ratings of mobile games on bar
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.
▪ Use the "Month" label for X-Axis and "Sales" for Y-Axis.
▪ Display legends.
▪ 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')
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()
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()
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))
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)