Shreyas CS Python Additional Lab
Shreyas CS Python Additional Lab
USN: 1BM22MCTMP050
Date: 26.04.2023
1) Write a program to create a Dataframe from an Excel sheet having the following details related to
Student:
USN, Name, Semester, CIE1_Mark, CIE2_Mark, CIE3 _Mark, Total Marks (Note: Max marks for each
CIE is 100, Total number of records=20)
Perform the following operations on the Dataframe:
a. Display the complete Data frame
b. Display only the first three records
c. Display only the last two records
d. Display the USN and Name of the Student who is the topper in CIE1.
e. Display the USN and Name of Students whose total is above 225.
f. Display the records in reverse order (From last record to first record)
d. Display the USN and Name of the Student who is the topper in CIE1.
import pandas as pd
marks=pd.read_csv("/Users/student/Downloads/sdata.csv")
x=marks['CIE1_MARKS'].max()
m=marks.loc[marks['CIE1_MARKS']==x,['USN','NAME']]
print(m)
e. Display the USN and Name of Students whose total is above 225.
import pandas as pd
marks=pd.read_csv("/Users/student/Downloads/sdata.csv")
x=marks['CIE1_MARKS'].max()
m=marks.loc[marks['TOTAL MARKS']>225,['USN','NAME']]
print(m)
f. Display the records in reverse order (From last record to first record)
df.iloc[::-1]
3) Assume a set of 10 students and their scores in 5 courses (E.g. (Rajiv, 60, 55, 90, 56, 85)) For each
course, you are required to obtain minimum, maximum, average, median, and Standard deviation
values. (Note: Do not use existing APIs/functions to find minimum, maximum, average, median, and
Standard deviation.)
def minimum(numbers):
min_value = numbers[0]
for number in numbers:
if number < min_value:
min_value = number
return min_value
def maximum(numbers):
max_value = numbers[0]
for number in numbers:
if number > max_value:
max_value = number
return max_value
def average(numbers):
sum_value = sum(numbers)
count = len(numbers)
return sum_value / count
def median(numbers):
numbers.sort()
count = len(numbers)
middle_index = count // 2
if count % 2 == 0:
median_value = (numbers[middle_index-1] + numbers[middle_index]) / 2
else:
median_value = numbers[middle_index]
return median_value
def standard_deviation(numbers):
mean_value = average(numbers)
deviations = [(number - mean_value) ** 2 for number in numbers]
variance = sum(deviations) / len(numbers)
standard_deviation_value = variance ** 0.5
return standard_deviation_value
for course_index in range(1, 6):
# Extract the scores for the course
course_scores = [student[course_index] for student in students]
course_minimum = minimum(course_scores)
course_maximum = maximum(course_scores)
course_average = average(course_scores)
course_median = median(course_scores)
course_standard_deviation = standard_deviation(course_scores)
print(f"Course {course_index}:")
print(f"Minimum: {course_minimum}")
print(f"Maximum: {course_maximum}")
print(f"Average: {course_average}")
print(f"Median: {course_median}")
print(f"Standard Deviation: {course_standard_deviation}")
print()
OUTPUT:
4) The favourite flavours of ice-cream for the children in a locality are given below.