0% found this document useful (0 votes)
18 views

Shreyas CS Python Additional Lab

This document contains instructions for several Python programming exercises involving dataframes and data analysis. It includes: 1) Creating a dataframe from an Excel file with student data and performing operations like displaying specific records, finding top scorers, and sorting. 2) Analyzing a dataset of student scores in 5 courses to find minimum, maximum, average, median, and standard deviation values for each course. 3) Creating a pie chart to visualize children's favorite ice cream flavors percentages from a given dataset.

Uploaded by

Sukruthi Kc
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

Shreyas CS Python Additional Lab

This document contains instructions for several Python programming exercises involving dataframes and data analysis. It includes: 1) Creating a dataframe from an Excel file with student data and performing operations like displaying specific records, finding top scorers, and sorting. 2) Analyzing a dataset of student scores in 5 courses to find minimum, maximum, average, median, and standard deviation values for each course. 3) Creating a pie chart to visualize children's favorite ice cream flavors percentages from a given dataset.

Uploaded by

Sukruthi Kc
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

SHREYAS C.S.

MCA 1st SEM

USN: 1BM22MCTMP050

PYTHON UNIT 4 LAB

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)

a. Display the complete Data frame:


import pandas as pd
data=pd.read_csv('/Users/student/Downloads/sdata.csv')
data
b. Display only the first three records
df=pd.read_csv("/Users/student/Downloads/sdata.csv")
df.head(n=3)

c. Display only the last two records


df=pd.read_csv("/Users/student/Downloads/sdata.csv")
df.tail(n=2)

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.)

students = [("Prabhu", 100,85,23,67,78),


("Sanjay", 45,76,92,43,85),
("Pavan", 45, 65, 70, 55, 80),
("Charan", 35,75,86,99,54),
("Varun",95,81,39,97,67),
("Aftab", 75, 80, 70, 85, 90),
("Ajith", 54,75,14,76,91),
("Sourav", 76,76,23,87,12),
("Kiran", 90,76,87,68,45),
("Achal", 99,98,97,96,95)]

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.

Flavours % of children prefering


the flavour
Vanilla 20
Strawberry 20
Chocolate 35
Kesar-Pista 10
Mango 15

Create a pie chart to represent the above information.

from matplotlib import pyplot as plt


import numpy as np
flavours=['Vanilla','Strawberry','Chocolate','Kesar-Pista','Mango']
pref=[20,20,35,10,15]
fig=plt.figure(figsize=(10,7))
plt.pie(pref,labels=flavours)
plt.show()

You might also like