0% found this document useful (0 votes)
7 views3 pages

Basic Data Science Lab Assignment

The document contains a series of Python code snippets demonstrating how to calculate the mean, mode, and median of various data sets using the statistics library. It includes examples with both predefined data and user input, showcasing the functionality of statistical calculations. Each code section is accompanied by its respective output, illustrating the results of the calculations.
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)
7 views3 pages

Basic Data Science Lab Assignment

The document contains a series of Python code snippets demonstrating how to calculate the mean, mode, and median of various data sets using the statistics library. It includes examples with both predefined data and user input, showcasing the functionality of statistical calculations. Each code section is accompanied by its respective output, illustrating the results of the calculations.
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

BASIC DATA SCIENCE LAB ASSIGNMENT-2

CODE:
import statistics
li=[1, 2, 3, 3, 2, 2, 2, 1]
print("The average of list values is:",end="")
print([Link](li))

OUTPUT:
The average of list values is:2

CODE:
from statistics import mode
from fractions import Fraction as fr
data1=(2,3,3,4,5,5,5,5,6,6,6,6,7)
data2=(2.4, 1.3, 1.3, 1.3, 2.4, 4.6)
data3=(fr(1,2), fr(1,2), fr(10,3), fr(1,2), fr(2,3))
data4=(-1,-2,-2,-2,-7,-7,-9)
data5=("red","blue","black","blue","black","black","brown")
print("Mode of data set 1 is %s" % (mode(data1)))
print("Mode of data set 2 is %s" % (mode(data2)))
print("Mode of data set 3 is %s" % (mode(data3)))
print("Mode of data set 4 is %s" % (mode(data4)))
print("Mode of data set 5 is %s" % (mode(data5)))

OUTPUT:
Mode of data set 1 is 5
Mode of data set 2 is 1.3
Mode of data set 3 is 1/2
Mode of data set 4 is -2
Mode of data set 5 is black

CODE:
from statistics import median
from fractions import Fraction as fr

data1=(2,3,3,4,5,5,5,5,6,6,6,6,7)
data2=(2.4, 1.3, 1.3, 1.3, 2.4, 4.6)
data3=(fr(1,2), fr(1,2), fr(10,3), fr(1,2), fr(2,3))

1
data4=(-1,-2,-2,-2,-7,-7,-9)
data5=(-1, -2, 1, 2, 9, -11)

print("Median of data set 1 is %s" % (median(data1)))


print("Median of data set 2 is %s" % (median(data2)))
print("Median of data set 3 is %s" % (median(data3)))
print("Median of data set 4 is %s" % (median(data4)))
print("Median of data set 5 is %s" % (median(data5)))

OUTPUT:
Median of data set 1 is 5
Median of data set 2 is 1.85
Median of data set 3 is 1/2
Median of data set 4 is -2
Median of data set 5 is 0.0

CODE:
import statistics
import random
def mean(n):
list=[]
for i in range(n):
ele=[Link](1,100)
[Link](ele)
print(list)
return [Link](list)
n=int(input("Enter the number of elements to be inserted:"))
mean(n)

OUTPUT:
Enter the number of elements to be inserted:10
[95, 19, 61, 37, 51, 75, 36, 82, 48, 16]
52

CODE:
import statistics

def user_median():
n = int(input("Enter the number of elements: "))
data = []
for i in range(n):

2
ele = float(input(f"Enter element {i+1}: "))
[Link](ele)
return [Link](data)

print("Median of the data set is:", user_median())

OUTPUT:
Enter the number of elements: 5
Enter element 1: 2
Enter element 2: 3
Enter element 3: 10
Enter element 4: 56
Enter element 5: 10
Median of the data set is: 10.0

CODE:
def user_mode():
n = int(input("Enter the number of elements: "))
data = []
for i in range(n):
ele = input(f"Enter element {i+1}: ")
[Link](ele)
try:
return [Link](data)
except [Link]:
return "No unique mode found"

print("Mode of the data set is:", user_mode())

OUTPUT:
Enter the number of elements: 5
Enter element 1: 1.5
Enter element 2: 2.5
Enter element 3: 2.5
Enter element 4: 3.6
Enter element 5: 9.2
Mode of the data set is: 2.5

You might also like