0% found this document useful (0 votes)
14 views20 pages

DAP Lab Manual (1)

The document outlines a Data Analytics Lab mini-project consisting of various Python programming tasks. These tasks include implementing linear search, inserting elements into a sorted list, demonstrating object-oriented programming concepts, and performing data manipulation and visualization using libraries like Pandas, NumPy, and Matplotlib. Additionally, it covers the generation of linear and logistic regression models, as well as time series analysis and data visualization with Seaborn.

Uploaded by

Niki Nikhil
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)
14 views20 pages

DAP Lab Manual (1)

The document outlines a Data Analytics Lab mini-project consisting of various Python programming tasks. These tasks include implementing linear search, inserting elements into a sorted list, demonstrating object-oriented programming concepts, and performing data manipulation and visualization using libraries like Pandas, NumPy, and Matplotlib. Additionally, it covers the generation of linear and logistic regression models, as well as time series analysis and data visualization with Seaborn.

Uploaded by

Niki Nikhil
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
You are on page 1/ 20

DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

1. Write a Python program to perform linear search


Program
arr = eval(input("Enter array elements: "))
key = int(input("Enter a element to be search: "))
for i in range(len(arr)):
if key == arr[i]:
print(f"Element {key} found at position {i}")
break
else:
print("Element not found")
Output
Enter array elements: [1,2,3,4,5]
Enter a element to be search: 5
Element 5 found at position 4

YOGEESH S 1
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

2. Write a Python program to insert an element into a sorted list


Program
lst = eval(input("Enter sorted list: "))
x = int(input("Enter a element to be insert: "))
for i in range(len(lst)):
if x < lst[i]:
lst.insert(i,x)
break
else:
lst.append(x)
print(lst)
Output
Enter sorted list: [1,2,3]
Enter a element to be insert: 3
[1, 2, 3, 3]

YOGEESH S 2
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

3. Write a python program using object oriented programming to


demonstrate encapsulation, overloading and inheritance
Program
class A:
_x = 5

class B(A):
def __init__(self,y):
self._y = y
def __add__(self,other):
return self._y + other._x
def display(self):
print(f"x = {self._x} y = {self._y}")

obj1 = B(5)
obj2 = B(6)
obj1.display()
obj2.display()
print(obj2 + obj1)
Output
x = 5 y = 5
x = 5 y = 6
11

YOGEESH S 3
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

4. Implement a python program to demonstrate


1) Importing Datasets
2) Cleaning the Data
3) Data frame manipulation using Numpy

import pandas as pd
import numpy as np

# 1. Importing Datasets
df = pd.read_csv('sample_data.csv')
print(df)

Name Age Salary


0 Alice 25.0 50000.0
1 Bob 30.0 60000.0
2 Charlie 22.0 NaN
3 David NaN 55000.0
4 Eve 28.0 70000.0
5 Frank 35.0 80000.0
6 Grace 27.0 65000.0
7 Hank 32.0 75000.0
8 Ivy 26.0 52000.0
9 Hank 32.0 75000.0
10 Ivy 26.0 52000.0

# 2. Cleaning the Data


df.duplicated()

0 False
1 False
2 False
3 False
4 False
5 False
6 False
7 False
8 False
9 True
10 True
dtype: bool

YOGEESH S 4
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

df = df.drop_duplicates()
df

df = df.fillna({'Age':int(np.mean(df['Age']))})
df

YOGEESH S 5
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

df = df.fillna({'Salary': np.mean(df['Salary'])})
df

YOGEESH S 6
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

5. Implement a python program to demonstrate the following using NumPy


a) Array manipulation, Searching, Sorting and splitting.
b) broadcasting and Plotting NumPy arrays

YOGEESH S 7
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

YOGEESH S 8
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

YOGEESH S 9
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

6. Implement a python program to demonstrate Data visualization with


various Types of Graphs using Numpy

import matplotlib.pyplot as plt


import numpy as np

x = np.array([2,4,6,8,10])
y = np.array([3,4,6,10,13])

plt.figure(figsize=(6,4))
plt.plot(x,y)
plt.title('Line Graph')
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.show()

plt.figure(figsize=(6,4))
plt.scatter(x,y)
plt.title('Scatter Graph')
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.show()

plt.figure(figsize=(6,4))
plt.bar(x,y)
plt.title('Bar Graph')
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.show()

plt.figure(figsize=(6,4))
plt.pie(x,labels=['a','b','c','d','e'])
plt.title('Pie Graph')
plt.xlabel('X axis')
plt.ylabel('Y axis')
plt.show()

YOGEESH S 10
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

YOGEESH S 11
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

YOGEESH S 12
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

7. Write a Python program that creates a mxn integer array and Prints its
attributes using matplotlib

import numpy as np
import matplotlib.pyplot as plt
m = 5
n = 7

arr = np.random.randint(100,size=(m,n))
print(arr)
print(arr.shape)
print(arr.size)
print(arr.T)
print(arr.dtype)
print(arr.ndim)
print(arr.itemsize)
print(arr.data)
plt.imshow(arr)
plt.show()

YOGEESH S 13
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

8. Write a Python program to demonstrate the generation of linear


regression models.
import numpy as np
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt

x = np.array([[1,2],[2,4],[3,6],[4,8],[5,10],[6,12]])
y = np.array([2,4,6,8,10,12])

model = LinearRegression()
model.fit(x,y)

print("Coefficent: ",model.coef_)
print("Intercept: ",model.intercept_)

newdata = np.array([[7,14]])
prediction = model.predict(newdata)
print(prediction)

plt.scatter(x[:,0],y,color='blue')
plt.plot(x[:,0],model.predict(x),color='red')
plt.show()

YOGEESH S 14
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

9. Write a Python program to demonstrate the generation of logistic


regression models using
import numpy as np
from sklearn.linear_model import LogisticRegression
import matplotlib.pyplot as plt

x = np.array([[1,2],[2,4],[3,6],[4,8],[5,10],[6,12]])
y = np.array([0,0,0,1,1,1])

model = LogisticRegression()
model.fit(x,y)

print("Coefficent: ",model.coef_)
print("Intercept: ",model.intercept_)

newdata = np.array([[7,14]])
prediction = model.predict(newdata)
print(prediction)

plt.scatter(x[:,0],y,color='blue')
plt.plot(x[:,0],model.predict(x),color='red')
plt.show()

YOGEESH S 15
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

10. Write a Python program to demonstrate Time series analysis with


Pandas.

YOGEESH S 16
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

YOGEESH S 17
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

11. Write a Python program to demonstrate Data Visualization using


Seaborn

YOGEESH S 18
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

YOGEESH S 19
DATA ANALYTICS LAB WITH MINI-PROJECT 22MCAL36

YOGEESH S 20

You might also like