0% found this document useful (0 votes)
3 views43 pages

Data Science

The document outlines various Python programming exercises, including numeric data types, arithmetic operations, list manipulation, tuples, dictionaries, correlation coefficients, and numpy mathematical functions. Each exercise includes an aim, algorithm, source code, and output demonstrating successful execution. The document serves as a comprehensive guide for practicing fundamental programming concepts in Python.

Uploaded by

h9686711
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)
3 views43 pages

Data Science

The document outlines various Python programming exercises, including numeric data types, arithmetic operations, list manipulation, tuples, dictionaries, correlation coefficients, and numpy mathematical functions. Each exercise includes an aim, algorithm, source code, and output demonstrating successful execution. The document serves as a comprehensive guide for practicing fundamental programming concepts in Python.

Uploaded by

h9686711
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

Ex.

No:01
DATE:07.01.26 Arithmetic Operations

Aim:
To write a program to demonstrate different numeric data types and arithmetic
Operations on numbers in python.

Algorithm:
STEP 1: Start by Jupyter Notebook

STEP 2: Declare the variable a bic and align the value for the three vaker

STEP 3: The types keyword used to define the type of the datatype .

STEP 4: Save the •py extenson program wing the

STEP 5: Stop the program.

SOURCE CODE:

A) Different numeric data types


a=10;
b=11.5;
c=2.05j;
print("a is Typeof",type(a));
print("b is Typeof",type(b));
print("c is Typeof",type(c));

Output:
a is Typeof <class 'int'>
b is Typeof <class 'float'>
c is Typeof <class 'complex'>
B) To perform different Arithmetic Operations on numbers in Python

a=int(input("Enter a value:"));
b=int(input("Enter b value:"));
print("Addition of a and b:",a+b);
print("Subtraction of a and b:",a-b);
print("Multiplication of a and b:",a*b);
print("Division of a and b:",a/b);
print("Reminder of a and b:",a%b);
print("Exponent of a and b:",a**b);
print("Floar division of a and b:",a//b);

Output:
Enter a value : 10
Enter b value: 20
Addition of a and b: 30
Subtraction of a and b: -10
Multiplication of a and b: 200
Division of a and b: 0.5
Reminder of a and b: 10
Exponent of a and b: 100000000000000000000
Floar division of a and b: 0

Result:
The program is executed successfully.
[Link]
DATE:07.01.26 Create, Append, and Remove Lists in Python

Aim
To write a program to create, append, and remove lists in Python.
Algorithm:
STEP 1: Start the program.
STEP 2: Create a two list and enter values into list
STEP 3: Join the two list and create new list
STEP 4: Print the new list
STEP 5: Remove an Value On existing an existing list
STEP 6: Save the program and end

SOURCE CODE:

pets=['cat','dog','rat','pig','tiger']
snakes=['python','anaconda','fish','cobra','mamba']
print('pets are:',pets)
print('snakes are:',snakes)
animals=pets +snakes
print('Animals are:',animals)
[Link]('fish')
print('updated snakes are:',snakes)
Output:
pets are: ['cat', 'dog', 'rat', 'pig', 'tiger']
snakes are: ['python', 'anaconda', 'fish', 'cobra', 'mamba']
Animals are: ['cat', 'dog', 'rat', 'pig', 'tiger', 'python', 'anaconda', 'fish', 'cobra',
'mamba']
updated snakes are: ['python', 'anaconda', 'cobra', 'mamba']

Result:
The program is executed successfully.
[Link]
DATE:21.01.26 Tuples and Dictionaries

Aim:
To write a program to demonstrate working with tuples and dictionaries in
Python.
Algorithm:
STEP 1: Start the Jyputer Notebook
STEP 2: Declare the variable and assign the Values
STEP 3: Using the print Statement print all the Tuples presented an In the
Variable
STEP 4: Using the Index value get the Second fruit value
STEP 5: Using the for loop check the 'Apple' is presented in the given list
STEP 6: Stop the program

SOURCE CODE:
T=("apple","banana","cherry","mango","grape")
print("\n Created tuple is:",T)
print("\n Second Tuple is:",T[1])
print("\n From 3-6 fruits are:",T[3:6])
print("\n List of all items in Tuple:")
for x in T:
print(x)
if"apple"in T:
print("yes,'apple'is in the fruits tuple")
print("\n Length of Tuple is:",len(T))
Output:
Created tuple is: ('apple', 'banana', 'cherry', 'mango', 'grape')
Second Tuple is: banana
From 3-6 fruits are: ('mango', 'grape')
List of all items in Tuple:
apple
banana
cherry
mango
grape
yes, 'apple' is in the fruits tuple
Length of Tuple is: 5

DICTIONARIES IN PYTHON

Algorithm:
STEP1: Start your program in Jupyter Notebook
STEP 2: Assign the values on the dictionaries
STEP 3: Dicionaries Contain the key value
STEP 4: By using the print statement displays the Dictionaries key and values
STEP 5: After displaying all the key pair Values the present in the dictionary stop
the program.
SOURCE CODE:

dict1={'StdNo':'532','StuName':'Naveen','StuAge':21,'StuCity':'Hyderabad'}
print("\n Dictionary is:",dict1)
print("\n Student Name is:",dict1['StuName'])
print("\n Student City is:",dict1['StuCity'])
print("\n All keys is Dictionary")
for x in dict1:
print(x)
print("\n All Values in Dictionary")
for x in dict1:
print(dict1[x])
dict1["Phno"]=85457854
print("\n Updated Dictionary is:",dict1)
dict1["StuName"]="Madhu"
print("\n Updated Dictionary is:",dict1)
[Link]("StuAge")
print("\n Upated Dictionary is:",dict1)
print("\n Length of the Dictionary is:",len(dict1))
dict2=[Link]()
print("\n New Dictionary is:",dict2)
[Link]()
print("\n Updated Dictionary is:",dict1)
Output:
Dictionary is: {'StdNo': '532', 'StuName': 'Naveen', 'StuAge': 21, 'StuCity':
'Hyderabad'}
Student Name is: Naveen
Student City is: Hyderabad
All keys is Dictionary
StdNo
StuName
StuAge
StuCity
All Values in Dictionary
532
Naveen
21
Hyderabad
Updated Dictionary is: {'StdNo': '532', 'StuName': 'Naveen', 'StuAge': 21,
'StuCity': 'Hyderabad', 'Phno': 85457854}
Updated Dictionary is: {'StdNo': '532', 'StuName': 'Madhu', 'StuAge': 21, 'StuCity':
'Hyderabad', 'Phno': 85457854}
Upated Dictionary is: {'StdNo': '532', 'StuName': 'Madhu', 'StuCity': 'Hyderabad',
'Phno': 85457854}
Length of the Dictionary is: 4
New Dictionary is: {'StdNo': '532', 'StuName': 'Madhu', 'StuCity': 'Hyderabad',
'Phno': 85457854}
Updated Dictionary is: {}
Result:
The program is executed successfully.
[Link]
DATE:28.01.26 Correlation Coefficient

Aim:
To write a program to compute correlation coefficient using python.
Algorithm:
STEP 1: Start the Jupyter Notebook
STEP 2: Import the numpy as np
STEP 3: Declare the variable along the radiant
STEP 4: Declare the variable 2 along with the random normal
STEP 5: Lastly, np. Corrcoef (var1,var2) then the array will be performed.

SOURCE CODE:
import numpy as np
[Link](100)
var1=[Link](0,10,50)
var2=var1+[Link](0,10,50)
[Link](var1,var2)

Output:
array([[1. , 0.3350184],
[0.3350184, 1. ]])

Result:
The program is executed successfully.
[Link]
DATE:28.01.26 Arrays, Array indexing

Aim:
To write a program to demonstrate arrays, array indexing using numpy in python.
Algorithm:
STEP1: Start your program.
STEP 2: Declare the variable using an array
STEP 3: using the index value like a[0], ....
STEP 4: Slicing the values are start: stop: step declare the number.

SOURCE CODE:
import array as arr
a=[Link]('i',[2,4,5,6])
print("First element is:",a[0])
print("Second element is:",a[1])
print("Third element is:",a[2])
print("Fourth element is:",a[3])
print("Last element is:",a[-1])
print("Second last element is:",a[-2])
print("Third last element is:",a[-3])
print("Fourth last element is:",a[-4])
print(a[0],a[1],a[2],a[3],a[-1],a[-2],a[-3],a[-4])
Output:
First element is: 2
Second element is: 4
Third element is: 5
Fourth element is: 6
Last element is: 6
Second last element is: 5
Third last element is: 4
Fourth last element is: 2
2 4566542

B) Deletion:
import numpy as np
a = [Link](20)
print("\n Array is:\n",a)
print("\n a[15]=",a[15])
print("\n a[-8:17:1]=",a[-8:17:1])
print("\n a[10:]=",a[10:])

Output:
Array is:
[ 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19]
a[15]= 15
a[-8:17:1]= [12 13 14 15 16]
a[10:]= [10 11 12 13 14 15 16 17 18 19]
C)Boolean Array Indexing:

import numpy as np
A=[Link]([4,7,3,4,2,8])
print(A==4)

Output:
[ True False False True False False]

Result:
The program is executed successfully.
[Link]
DATE:04.02.26 Numpy mathematical functions

Aim:
To write a program to demonstrate Numpy mathematical functions.
Algorithm:
STEP 1: start the program.
STEP 2: Import the numpy packages in the program
STEP 3: Perform the mathematical functions like +, -, *, /
STEP 4: calculate exponential value using exp array = [Link](arr).
STEP 5: Perform matrix multiptication and standard deviation
STEP 6: Run and save the program

SOURCE CODE:
A) Basic Arithmetic functions
import numpy as np
a=[Link]([10,20,30])
b=[Link]([5,10,15])
addition=a+b
subtraction=a-b
multiplication=a*b
division=a/b
print("Addition:",addition)
print("Subtraction:",subtraction)
print("Multiplication:",multiplication)
print("Division:",division)

Output:
Addition: [15 30 45]
Subtraction: [ 5 10 15]
Multiplication: [ 50 200 450]
Division: [2. 2. 2.]

B) Trigonometric Functions
import numpy as np
angles=[Link]([0,[Link]/4,[Link]/2,[Link]])
sine_values=[Link](angles)
cosine_values=[Link](angles)
tanget_values=[Link](angles)
print("sine values:",sine_values)
print("cosine values:",cosine_values)
print("tanget values:",tanget_values)

Output:
sine values: [0.00000000e+00 7.07106781e-01 1.00000000e+00 1.22464680e-16]
cosine values: [ 1.00000000e+00 7.07106781e-01 6.12323400e-17 -
1.00000000e+00]
tanget values: [ 0.00000000e+00 1.00000000e+00 1.63312394e+16 -
1.22464680e-16]
C) Exponential:
import numpy as np
arr=[Link]([1,2,3])
exp_array=[Link](arr)
print("Exponential values:",exp_array)

Output:
Exponential Values: [2.71828183 7.3890561 20.0855 3692]

D) Logarithmic Functions
import numpy as np
arr=[Link]([1,2,10])
log_array=[Link](arr)
log10_array=np.log10(arr)
print("Natural logarithm values:",log_array)
print("Base-10 logarithm values:",log10_array)

Output:
Natural logarithm values: [0.0.69314718 2.30258509)
Base-10 logarithm values: [0. 0.301031.]

E) Statistical Functions in NumPy


import numpy as np
arr=[Link]([1,2,3,4,5])
mean_value=[Link](arr)
median_value=[Link](arr)
print("Mean value:",mean_value)
print("Median value:",median_value)
Output:
Mean value: 3.0
Median value: 3.0

F) Standard Deviation and Variance


import numpy as np
arr=[Link]([1,2,3,4,5])
std_dev=[Link](arr)
variance=[Link](arr)
print("Standard deviation:",std_dev)
print("Variance:",variance)

Output:
Standard deviation: 1.4142135623730951
Variance: 2.0

G) Dot Product
import numpy as np
arr1=[Link]([1,2])
arr2=[Link]([3,4])
dot_product=[Link](arr1,arr2)
print("Dot product:",dot_product)

Output:
Dot product: 11

H) Matrix Multiplication
import numpy as np
A=[Link]([[1,2],[3,4]])
B=[Link]([[5,6],[7,8]])
c=[Link](A,B)
print(c)

Output:
[[19 22]
[43 50]]

Result:
Thus, the program is executed successfully.
[Link]
DATE:11.02.26 Weighted Averages in Python

Aim:
To write a program to compute weighted averages in python or using
Numpy.
Algorithm:
STEP 1: Start a program.
STEP 2: import pandas as pd.
STEP 3: list your values inside your variable list.
STEP 4: Now, store the pd Dataprame constructor on the list 'df'.
STEP 5: Then print your results stored in list varaible 'df'.
STEP 6: End a program.

SOURCE CODE:
A)1-D Array:
import numpy as np
a=[Link]([3,4,2,3,90,34])
weights=[Link]([2,3,1,5,7,6])
print("The input array:",a)
print("The dimension of the array:",[Link](a))
avg=[Link](a)
print("The average of the given 1-d array:",avg)
weg=[Link](a,weights=weights)
print("weighted average of the array:",weg)
Output:
The input array: [ 3 4 2 3 90 34]
The dimension of the array: 1
The average of the given 1-d array: 22.666666666666668
weighted average of the array: 36.208333333333336

B)2-D Array:
import numpy as np
a=[Link]([[34,23],[90,34]])
weights=[Link]([[2,3],[5,7]])
print("The input array:",a)
print("The dimension of the array:",[Link](a))
avg=[Link](a)
print("The average of the given 2-d array:",avg)
weg=[Link](a,weights=weights)
print("Weighted average of the array:",weg)

Output:
The input array: [[34 23]
[90 34]]
The dimension of the array: 2
The average of the given 2-d array: 45.25
Weighted average of the array: 48.529411764705884
C) 3-D Array:
import numpy as np
a=[Link]([[[3,4],[2,3]],[[90,34],[78,23]]])
weights=[Link]([[[3,4],[2,3]],[[90,34],[78,23]]])
print("The input array:",a)
print("The dimension of the array:",[Link](a))
avg=[Link](a)
print("The average of the given 3-d array:",avg)
weg=[Link](a,weights=weights)
print("weighted average of thee array:",weg)

Output:
The input array: [[[ 3 4]
[ 2 3]]
[[90 34]
[78 23]]]
The dimension of the array: 3
The average of the given 3-d array: 29.625
weighted average of thee array: 67.11814345991561

Result:
Thus, the program is executed successfully.
[Link]
DATE:18.02.26 Mean, Median, Mode

Aim:
To write a program to create pandas dataframe using a list of elements.
Algorithm:
STEP 1: Start a program
STEP 2: import pandas as pd
STEP 3: list your values inside your variable list
STEP 4: now, store the pd Dataframe constructor on the list 'df'.
STEP 5: Then print your results stored in list varaible 'df'.
STEP 6: End a program

SOURCE CODE:
import pandas as pd
lst=['Geeks','For','Geeks','is','portal','for','Geeks']
df=[Link](lst)
print(df)

Output:
0
0 Geeks
1 For
2 Geeks
3 is
4 portal
5 for
6 Geeks
Result: Thus, the program is executed successfully.
[Link]
DATE:18.02.26 Mean, Median, Mode

AIM:
Write a program to compute summary statistics such as mean, median, mode,
standard deviation and variance using pandas.
Algorithm:
STEP 1: Start a program
STEP 2: Import pandas library using import keyword
STEP 3: Create a dataframe
STEP 4: Print the result or dataframe
STEP 5: Calculate mean,median,mode values
STEP 6: Print the values.

SOURCE CODE:
import pandas as pd
data={'A':[1,2,3,4,5],
'B':[10,20,15,25,30]}
df=[Link](data)
print(df)

Output:
A B
0 1 10
1 2 20
2 3 15
3 4 25
4 5 30
MEAN
import numpy
speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]
x = [Link](speed)
print(x)

Output:
89.76923076923077

MEDIAN

The median value is the value in the middle, after you have sorted all the
values: 77, 78, 85, 86, 86, 86, 87, 87, 88, 94, 99, 103, 111
Use the NumPy median() method to find the middle value:

import numpy
speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]
x = [Link](speed)
print(x)

Output:
87.0
MODE
The Mode value is the value that appears the most number of times: 99, 86,
87, 88, 111, 86, 103, 87, 94, 78, 77, 85, 86 = 86

from scipy import stats


speed = [99,86,87,88,111,86,103,87,94,78,77,85,86]
x = [Link](speed)
print(x)

Output:
ModeResult(mode=np.int64(86), count=np.int64(3)

Result:
Thus, the program is executed successfully.
[Link]
DATE:25.02.26 Univariate Analysis
Aim:
To write a program to perform univariate data analysis.
Algorithm:
STEP 1: Start a program
STEP 2: Import the necessary libraries like pandas and seaborn
STEP 3: Read the csv file
STEP 4: Print the result.
STEP 5: Perform the histogram, Barchart. and piechart
STEP 6: End a program

SOURCE CODE:
import pandas as pd
import seaborn as sns
data=pd.read_csv('/content/employee_salary_dataset.csv')
print([Link]())

Output:
HISTOGRAM:
[Link](data['Age'])

Output:
<Axes: xlabel='Age', ylabel='Count'>
BAR PLOT:
[Link](data['Gender'])

Output:
<Axes: xlabel='count', ylabel='Gender'>

PIE CHART:
import [Link] as plt
x=data['Experience_Years'].value_counts()
[Link]([Link],
labels=[Link],
autopct='%1.1f%%')
[Link]()
Output:

Result:
Thus, the program is executed successfully.
[Link].11
DATE:11.03.26 Bivariate & Multivariate Analysis

Aim:
To write a program to perform Bivariate & Mutivariate data analysis.
Algorithm:
STEP 1: Start a program
STEP 2: Import the necessary libraries like pandas, seaborn and matplotlib
STEP 3: Read the csv file
STEP 4: Print the result
STEP 5: Perform bivariate and multi-variate analysis
STEP 6: End a program

SOURCE CODE:
import pandas as pd
import seaborn as sns
df=pd.read_csv("/content/employee_salary_dataset.csv")
print([Link]())

Output:
BIVARIATE ANALYSIS

CATEGORICAL V/S NUMERICAL

import [Link] as plt


[Link](figsize=(15,5))
[Link](x=df['Department'],y=df['Experience_Years'])
[Link](rotation=60)
[Link]()

Output:
NUMERICAL V/S NUMERICAL

[Link](x=df['Experience_Years'],
y=df['Age'])

Output:
<Axes: xlabel='Experience_Years', ylabel='Age'>
CATEGORICAL V/S CATEGORICAL

[Link](x=df['Department'],hue=df['Education_Level'])

Output:
<Axes: xlabel='Department', ylabel='count'>

MULTIVARIATE ANALYSIS

from sklearn import datasets,decomposition


import seaborn as sns
iris=datasets.load_iris()
X=[Link]
y=[Link]
pca=[Link](n_components=2)
[Link](X)
X=pca.fit_transform(X)
[Link](x=X[:,0],y=X[:,1],hue=y)

Output:
HEATMAP:

[Link]([Link](numeric_only=True),annot=True)

Output:

Result:
Thus, the program is executed successfully.
[Link]
DATE:18.03.26 Basic Plots

Aim:
To write a program to perform the basic plots.
Algorithm:
STEP 1: Collect or input the dataset.
STEP 2: Choose a plotting library.
STEP 3: Create a new plot or figure.
STEP 4: Set plot title, axis labels, and other properties.
STEP 5: Use a display function and end.

SOURCE CODE:
import pandas as pd
import seaborn as sns
df=pd.read_csv('/content/gym_members_exercise_tracking_synthetic_data.csv')
print([Link]())

Output:
SIMPLE PLOTS:

import pandas as np
import [Link] as plt
x=[Link]([80,85,90,95,100,105,110,115,120,125])
y=[Link]([240,250,260,270,280,290,300,310,320,330])
[Link](x,y)
[Link]("Workout_Type vs calorie burnage")
[Link]("Workout_Type")
[Link]("Calories_Burned")
[Link]()
Output:

GRID LINES:

import pandas as np
import [Link] as plt
x=[Link]([80,85,90,95,100,105,110,115,120,125])
y=[Link]([240,250,260,270,280,290,300,310,320,330])
[Link]("Workout_Type vs calorie burnage")
[Link]("Workout_Type")
[Link]("Calories_Burned")
[Link](x,y)
[Link]()
[Link]()
Output:

SCATTER PLOT:

import [Link] as plt


import numpy as np
x=[Link]([5,7,8,7,2,17,2,9,4,11,12,9,6])
y=[Link]([99,86,87,88,111,86,103,87,94,78,77,85,86])
[Link](x,y)
[Link]()
Output:

SCATTER PLOT WITH ANNOTATION:

import pandas as pd
import numpy as np
import [Link] as plt
import seaborn as sns
df=[Link]({
'x':[1,1.5,3,4,5],
'y':[5,15,5,10,2],
'group':['Silver','Gold','B','C','D']})
[Link](data=df,x="x",y="y",s=200)
for line in range(0,[Link][0]):
[Link](
df["x"][line]+0.2,
df["y"][line],
df["group"][line],
ha='left',
weight='bold')
[Link]()

Output:

LINE STYLES AND COLORS:

from matplotlib import pyplot as plt


import numpy as np
linestyles=["-","--","-.",":"]
x=[Link](-10,10,100)
for i,ls in enumerate(linestyles):
y=3.5-2.3*(x+i)+0.5*(x+i)**2
[Link](x,y,linestyle=ls,label=ls)
[Link]()
[Link]()

Output:

BAR PLOT:

import [Link] as plt


import numpy as np
x=[Link](["A","B","C","D"])
y=[Link]([3,8,1,10])
[Link](x,y,color="#4CAF50")
[Link]()
Output:

Result:
Thus, the program is executed successfully.

You might also like