Data Analytics Using Python Lab Manual
Data Analytics Using Python Lab Manual
Lab program 1:
def linear_Search(list,n,x):
array = [1 ,3, 5, 4, 7, 9]
n = len(array)
x=int(input("enter the item"))
res = linear_Search(list,n,x)
if(res == -1):
print("Element not found")
else:
print("Element found at index: ", res)
OUTPUT:
enter the item 9
Element found at index: 5
Lab program 2:
index = len(list)
# Searching for the position
for i in range(len(list)):
if list[i] > n:
index = i
break
# Driver function
list = [1, 2, 4]
n=3
print(insert(list, n))
output:
[1, 2, 3, 4]
Lab program 3:
Write a python program using object oriented programming to demonstrate encapsulation, overloading
and inheritance
##parent class
class Operations:
#constructor
def __init__(self,a,b):
self.a=a
self.b=b
def add(self):
sum=self.a+self.b
print ("sum of a and b is : ", sum)
#Child class
class Myclass(Operations):
#constructor
def _init__(self,a,b):
#invoking parent class constructor
super(self,Operations).__init__(a,b)
self.a=a
self.b=b
def sub(self):
sub=self.a-self.b
print("Subtraction of C and D is : ", sub)
ob1=Myclass(20,30)
ob2=Myclass("ONE","TWO")
ob1.add()#to sum up integers
ob2.add()#to sum up String
ob1.sub()
Shwetha shri K - Asst.Professor Page 2
Data Analytics Lab Manual DEPT OF MCA,EWIT
OUTPUT:
sum of a and b is : 70
sum of a and b is : ONETWO
Subtraction of C and D is : -10
Lab program 5:
a = np.array([[1, 4, 2],
[3, 4, 6],
[0, -1, 5]])
#array before sorting
print ("Array elements before sorting:\n")
print(a)
# sorted array
#Splitting of Arrays
b = np.array([[3, 4, 5],
[6, 7, 8],
[9, 10, 11]])
print(b)
print(b[0:3,1])
[[ 1 4 2]
[ 3 4 6]
[ 0 -1 5]]
Array elements in sorted order:
[-1 0 1 2 3 4 4 5 6]
i = (array([1]), array([2]))
Column wise sort by applying merge-sort:
[[ 0 -1 2]
[ 1 4 5]
[ 3 4 6]]
[[ 3 4 5]
[ 6 7 8]
[ 9 10 11]]
[ 4 7 10]
import numpy as np
print(A)
b=4
print(b)
C=A+b
print(C)
y_sin = np.sin(x)
y_cos = np.cos(x)
plt.plot(x, y_sin)
plt.plot(x, y_cos)
plt.legend(['Sine', 'Cosine'])
plt.show()
OUTPUT:
import pandas as pd
df.hist()
# show plot
plt.show()
(Histogram)
df.plot.bar()
plt.bar(df['Age'], df['Sales'])
plt.xlabel("Age")
plt.ylabel("Sales")
plt.show()
OUTPUT:
(Column Chart)