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

Case Study Assignment 5

The document contains Python code for analyzing student data and cricket scores. It includes generating pie charts for the highest marks achieved in each department and the number of students in each department, as well as comparing India's cricket performance against its best opponent. The code uses pandas for data manipulation and matplotlib for visualization.

Uploaded by

Manasa P M
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)
4 views3 pages

Case Study Assignment 5

The document contains Python code for analyzing student data and cricket scores. It includes generating pie charts for the highest marks achieved in each department and the number of students in each department, as well as comparing India's cricket performance against its best opponent. The code uses pandas for data manipulation and matplotlib for visualization.

Uploaded by

Manasa P M
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/ 3

How many achieved highest marks in each department

import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('students_data.csv')
highest_marks = data.groupby('Major')['SGPA'].max()
plt.figure(figsize=(8, 6))
plt.pie(highest_marks, labels=highest_marks.index, autopct='%1.1f%%', startangle=140)
plt.show()
Number of students in each department
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv('students_data.csv')
department_counts = data['Major'].value_counts()
plt.figure(figsize=(8, 6))
plt.pie(department_counts, labels=department_counts.index, autopct='%1.1f%%',
startangle=140)
plt.show()
Comparing how India won against its best opponent in cricket
import matplotlib.pyplot as plt
with open('cricketscore.txt', 'r') as file:
lines = file.readlines()[1:]
highest_score = 0
best_opponent = ""
opponent_score = 0
for line in lines:
parts = line.strip().split(',')
if len(parts) < 5:
continue
try:
score = int(parts[4].split('/')[0].split()[-1])
if score > highest_score:
highest_score = score
best_opponent = parts[2]
opponent_score = highest_score * 0.75 # Assuming opponent scored 75% of India’s
runs
except ValueError:
continue
labels = [f'India ({highest_score})', f'{best_opponent} (~{int(opponent_score)})']
sizes = [highest_score, opponent_score]
plt.pie(sizes, labels=labels, autopct='%1.1f%%', startangle=140)
plt.show()

You might also like