11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
localhost:8888/notebooks/[Link]?kernel_name=python3 1/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
localhost:8888/notebooks/[Link]?kernel_name=python3 2/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
In [2]: import pandas as pd
# Load the Excel file
file_path = '[Link]'
data = pd.read_excel(file_path)
# Display the first few rows to understand the data structure
print("Data preview:\n", [Link]())
# Step 1: Analyze Grade Distribution
def calculate_grade_distribution(data):
grades = ['A1', 'A2', 'B1', 'B2', 'C1', 'C2', 'D', 'E']
grade_counts = {grade: 0 for grade in grades}
# Count the number of students in each grade category
for score in data['Percentage']:
if score >= 90:
grade_counts['A1'] += 1
elif score >= 80:
grade_counts['A2'] += 1
elif score >= 70:
grade_counts['B1'] += 1
elif score >= 60:
grade_counts['B2'] += 1
elif score >= 50:
grade_counts['C1'] += 1
elif score >= 40:
grade_counts['C2'] += 1
elif score >= 33:
grade_counts['D'] += 1
else:
grade_counts['E'] += 1
return grade_counts
# Calculate and display grade distribution
grade_distribution = calculate_grade_distribution(data)
print("\nGrade Distribution:\n", grade_distribution)
# Step 2: Calculate Performance Index (PI)
def calculate_performance_index(grade_distribution):
# Define weight for each grade
weights = {'A1': 8, 'A2': 7, 'B1': 6, 'B2': 5, 'C1': 4, 'C2': 3, 'D': 2
# Compute weighted score
weighted_score = sum(grade_distribution[grade] * weights[grade] for gra
total_students = sum(grade_distribution.values())
# Calculate PI
performance_index = (weighted_score / (total_students * 8)) * 100
return performance_index
# Display Performance Index
pi = calculate_performance_index(grade_distribution)
print("\nPerformance Index (PI):", round(pi, 2), "%")
# Step 3: Identify Highest Scorer
highest_scorer = [Link][data['Percentage'].idxmax()]
print("\nHighest Scorer:\n", highest_scorer[['Name', 'Father’s Name', 'Cate
# Step 4: Calculate Subject-wise Grade Distribution (example for English)
localhost:8888/notebooks/[Link]?kernel_name=python3 3/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
subject = 'English' # Replace with other subjects as needed
def subject_grade_distribution(subject):
subject_grades = data[[subject]]
counts = {
'A1': len(subject_grades[subject_grades[subject] >= 90]),
'A2': len(subject_grades[(subject_grades[subject] >= 80) & (subject
'B1': len(subject_grades[(subject_grades[subject] >= 70) & (subject
'B2': len(subject_grades[(subject_grades[subject] >= 60) & (subject
'C1': len(subject_grades[(subject_grades[subject] >= 50) & (subject
'C2': len(subject_grades[(subject_grades[subject] >= 40) & (subject
'D': len(subject_grades[(subject_grades[subject] >= 33) & (subject_
'E': len(subject_grades[subject_grades[subject] < 33]),
}
return counts
# Display English Grade Distribution
english_distribution = subject_grade_distribution('English')
print("\nEnglish Grade Distribution:\n", english_distribution)
Data preview:
Roll No Gender Name HINDI CORE Grade ENGLISH CORE Grad
e.1 \
0 13629815 F ARADHNA SHARMA NaN NaN 89
A2
1 13629816 M ARUN SHARMA NaN NaN 85
B1
2 13629817 F BHUMI ABROL NaN NaN 79
B2
3 13629818 M DHAIRYA JANDIAL NaN NaN 69
C2
4 13629819 M KRISH KHAJURIA NaN NaN 72
C1
INFORMATICS PRACTICES (NEW) Grade.2 PHYSICAL EDUCATION ... \
0 95.0 A2 69 ...
1 91.0 B1 67 ...
2 90.0 B1 66 ...
3 91.0 B1 65 ...
4 84.0 B2 54 ...
POLITICAL SCIENCE Grade.9 GEOGRAPHY Grade.10 GR1 GR2 GR3 Result \
0 NaN NaN NaN NaN A1 A1 A1 PASS
1 NaN NaN NaN NaN A2 A2 A2 PASS
2 NaN NaN NaN NaN A2 A1 A1 PASS
3 NaN NaN NaN NaN A1 A2 A2 PASS
4 NaN NaN NaN NaN A2 A2 A2 PASS
Best 5 percentage Compartment Subject
0 87.4 NaN
1 81.2 NaN
2 79.2 NaN
3 74.6 NaN
4 69.6 NaN
[5 rows x 31 columns]
localhost:8888/notebooks/[Link]?kernel_name=python3 4/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
-------------------------------------------------------------------------
--
KeyError Traceback (most recent call las
t)
~\anaconda\lib\site-packages\pandas\core\indexes\[Link] in get_loc(self,
key, method, tolerance)
3628 try:
-> 3629 return self._engine.get_loc(casted_key)
3630 except KeyError as err:
~\anaconda\lib\site-packages\pandas\_libs\[Link] in pandas._libs.inde
[Link].get_loc()
~\anaconda\lib\site-packages\pandas\_libs\[Link] in pandas._libs.inde
[Link].get_loc()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.[Link]
tHashTable.get_item()
pandas\_libs\hashtable_class_helper.pxi in pandas._libs.[Link]
tHashTable.get_item()
KeyError: 'Percentage'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call las
t)
~\AppData\Local\Temp\ipykernel_8836\[Link] in <module>
35
36 # Calculate and display grade distribution
---> 37 grade_distribution = calculate_grade_distribution(data)
38 print("\nGrade Distribution:\n", grade_distribution)
39
~\AppData\Local\Temp\ipykernel_8836\[Link] in calculate_grade_dist
ribution(data)
14
15 # Count the number of students in each grade category
---> 16 for score in data['Percentage']:
17 if score >= 90:
18 grade_counts['A1'] += 1
~\anaconda\lib\site-packages\pandas\core\[Link] in __getitem__(self, ke
y)
3503 if [Link] > 1:
3504 return self._getitem_multilevel(key)
-> 3505 indexer = [Link].get_loc(key)
3506 if is_integer(indexer):
3507 indexer = [indexer]
~\anaconda\lib\site-packages\pandas\core\indexes\[Link] in get_loc(self,
key, method, tolerance)
3629 return self._engine.get_loc(casted_key)
3630 except KeyError as err:
-> 3631 raise KeyError(key) from err
3632 except TypeError:
3633 # If we have a listlike key, _check_indexing_erro
r will raise
localhost:8888/notebooks/[Link]?kernel_name=python3 5/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
KeyError: 'Percentage'
localhost:8888/notebooks/[Link]?kernel_name=python3 6/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
localhost:8888/notebooks/[Link]?kernel_name=python3 7/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
In [3]: import pandas as pd
# Load the Excel file
file_path = '[Link]'
data = pd.read_excel(file_path)
# Preview data structure
print("Data preview:\n", [Link]())
# Step 1: Analyze Grade Distribution
def calculate_grade_distribution(data):
grades = ['A1', 'A2', 'B1', 'B2', 'C1', 'C2', 'D', 'E']
grade_counts = {grade: 0 for grade in grades}
# Count the number of students in each grade category
for score in data['Best 5 percentage']:
if score >= 90:
grade_counts['A1'] += 1
elif score >= 80:
grade_counts['A2'] += 1
elif score >= 70:
grade_counts['B1'] += 1
elif score >= 60:
grade_counts['B2'] += 1
elif score >= 50:
grade_counts['C1'] += 1
elif score >= 40:
grade_counts['C2'] += 1
elif score >= 33:
grade_counts['D'] += 1
else:
grade_counts['E'] += 1
return grade_counts
# Calculate and display grade distribution
grade_distribution = calculate_grade_distribution(data)
print("\nGrade Distribution:\n", grade_distribution)
# Step 2: Calculate Performance Index (PI)
def calculate_performance_index(grade_distribution):
# Define weight for each grade
weights = {'A1': 8, 'A2': 7, 'B1': 6, 'B2': 5, 'C1': 4, 'C2': 3, 'D': 2
# Compute weighted score
weighted_score = sum(grade_distribution[grade] * weights[grade] for gra
total_students = sum(grade_distribution.values())
# Calculate PI
performance_index = (weighted_score / (total_students * 8)) * 100
return performance_index
# Display Performance Index
pi = calculate_performance_index(grade_distribution)
print("\nPerformance Index (PI):", round(pi, 2), "%")
# Step 3: Identify Highest Scorer
highest_scorer = [Link][data['Best 5 percentage'].idxmax()]
print("\nHighest Scorer:\n", highest_scorer[['Name', 'Father’s Name', 'Cate
# Step 4: Calculate Subject-wise Grade Distribution (example for English)
localhost:8888/notebooks/[Link]?kernel_name=python3 8/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
subject = 'ENGLISH CORE' # Replace with other subjects as needed
def subject_grade_distribution(subject):
subject_grades = data[[subject]]
counts = {
'A1': len(subject_grades[subject_grades[subject] >= 90]),
'A2': len(subject_grades[(subject_grades[subject] >= 80) & (subject
'B1': len(subject_grades[(subject_grades[subject] >= 70) & (subject
'B2': len(subject_grades[(subject_grades[subject] >= 60) & (subject
'C1': len(subject_grades[(subject_grades[subject] >= 50) & (subject
'C2': len(subject_grades[(subject_grades[subject] >= 40) & (subject
'D': len(subject_grades[(subject_grades[subject] >= 33) & (subject_
'E': len(subject_grades[subject_grades[subject] < 33]),
}
return counts
# Display English Grade Distribution
english_distribution = subject_grade_distribution('ENGLISH CORE')
print("\nEnglish Grade Distribution:\n", english_distribution)
localhost:8888/notebooks/[Link]?kernel_name=python3 9/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
Data preview:
Roll No Gender Name HINDI CORE Grade ENGLISH CORE Grad
e.1 \
0 13629815 F ARADHNA SHARMA NaN NaN 89
A2
1 13629816 M ARUN SHARMA NaN NaN 85
B1
2 13629817 F BHUMI ABROL NaN NaN 79
B2
3 13629818 M DHAIRYA JANDIAL NaN NaN 69
C2
4 13629819 M KRISH KHAJURIA NaN NaN 72
C1
INFORMATICS PRACTICES (NEW) Grade.2 PHYSICAL EDUCATION ... \
0 95.0 A2 69 ...
1 91.0 B1 67 ...
2 90.0 B1 66 ...
3 91.0 B1 65 ...
4 84.0 B2 54 ...
POLITICAL SCIENCE Grade.9 GEOGRAPHY Grade.10 GR1 GR2 GR3 Result \
0 NaN NaN NaN NaN A1 A1 A1 PASS
1 NaN NaN NaN NaN A2 A2 A2 PASS
2 NaN NaN NaN NaN A2 A1 A1 PASS
3 NaN NaN NaN NaN A1 A2 A2 PASS
4 NaN NaN NaN NaN A2 A2 A2 PASS
Best 5 percentage Compartment Subject
0 87.4 NaN
1 81.2 NaN
2 79.2 NaN
3 74.6 NaN
4 69.6 NaN
[5 rows x 31 columns]
Grade Distribution:
{'A1': 2, 'A2': 8, 'B1': 15, 'B2': 9, 'C1': 2, 'C2': 0, 'D': 0, 'E': 0}
Performance Index (PI): 74.65 %
localhost:8888/notebooks/[Link]?kernel_name=python3 10/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
-------------------------------------------------------------------------
--
KeyError Traceback (most recent call las
t)
~\AppData\Local\Temp\ipykernel_8836\[Link] in <module>
57 # Step 3: Identify Highest Scorer
58 highest_scorer = [Link][data['Best 5 percentage'].idxmax()]
---> 59 print("\nHighest Scorer:\n", highest_scorer[['Name', 'Father’s Na
me', 'Category', 'Best 5 percentage']])
60
61 # Step 4: Calculate Subject-wise Grade Distribution (example for
English)
~\anaconda\lib\site-packages\pandas\core\[Link] in __getitem__(self, k
ey)
982 return self._get_values(key)
983
--> 984 return self._get_with(key)
985
986 def _get_with(self, key):
~\anaconda\lib\site-packages\pandas\core\[Link] in _get_with(self, ke
y)
1022
1023 # handle the dup indexing case GH#4246
-> 1024 return [Link][key]
1025
1026 def _get_values_tuple(self, key):
~\anaconda\lib\site-packages\pandas\core\[Link] in __getitem__(self,
key)
965
966 maybe_callable = com.apply_if_callable(key, [Link])
--> 967 return self._getitem_axis(maybe_callable, axis=axis)
968
969 def _is_scalar_access(self, key: tuple):
~\anaconda\lib\site-packages\pandas\core\[Link] in _getitem_axis(sel
f, key, axis)
1192 raise ValueError("Cannot index with multidime
nsional key")
1193
-> 1194 return self._getitem_iterable(key, axis=axis)
1195
1196 # nested tuple slicing
~\anaconda\lib\site-packages\pandas\core\[Link] in _getitem_iterable
(self, key, axis)
1130
1131 # A collection of keys
-> 1132 keyarr, indexer = self._get_listlike_indexer(key, axis)
1133 return [Link]._reindex_with_indexers(
1134 {axis: [keyarr, indexer]}, copy=True, allow_dups=True
~\anaconda\lib\site-packages\pandas\core\[Link] in _get_listlike_ind
exer(self, key, axis)
1328 axis_name = [Link]._get_axis_name(axis)
1329
-> 1330 keyarr, indexer = ax._get_indexer_strict(key, axis_name)
1331
1332 return keyarr, indexer
localhost:8888/notebooks/[Link]?kernel_name=python3 11/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
~\anaconda\lib\site-packages\pandas\core\indexes\[Link] in _get_indexer_
strict(self, key, axis_name)
5794 keyarr, indexer, new_indexer = self._reindex_non_uniq
ue(keyarr)
5795
-> 5796 self._raise_if_missing(keyarr, indexer, axis_name)
5797
5798 keyarr = [Link](indexer)
~\anaconda\lib\site-packages\pandas\core\indexes\[Link] in _raise_if_mis
sing(self, key, indexer, axis_name)
5857
5858 not_found = list(ensure_index(key)[missing_mask.nonze
ro()[0]].unique())
-> 5859 raise KeyError(f"{not_found} not in index")
5860
5861 @overload
KeyError: "['Father’s Name', 'Category'] not in index"
localhost:8888/notebooks/[Link]?kernel_name=python3 12/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
localhost:8888/notebooks/[Link]?kernel_name=python3 13/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
In [5]: import pandas as pd
# Load the Excel file
file_path = '[Link]'
data = pd.read_excel(file_path)
# Step 1: Analyze Grade Distribution
def calculate_grade_distribution(data):
grades = ['A1', 'A2', 'B1', 'B2', 'C1', 'C2', 'D', 'E']
grade_counts = {grade: 0 for grade in grades}
# Count the number of students in each grade category
for score in data['Best 5 percentage']:
if score >= 90:
grade_counts['A1'] += 1
elif score >= 80:
grade_counts['A2'] += 1
elif score >= 70:
grade_counts['B1'] += 1
elif score >= 60:
grade_counts['B2'] += 1
elif score >= 50:
grade_counts['C1'] += 1
elif score >= 40:
grade_counts['C2'] += 1
elif score >= 33:
grade_counts['D'] += 1
else:
grade_counts['E'] += 1
return grade_counts
# Calculate and display grade distribution
grade_distribution = calculate_grade_distribution(data)
print("\nGrade Distribution:\n", grade_distribution)
# Step 2: Calculate Performance Index (PI)
def calculate_performance_index(grade_distribution):
# Define weight for each grade
weights = {'A1': 8, 'A2': 7, 'B1': 6, 'B2': 5, 'C1': 4, 'C2': 3, 'D': 2
# Compute weighted score
weighted_score = sum(grade_distribution[grade] * weights[grade] for gra
total_students = sum(grade_distribution.values())
# Calculate PI
performance_index = (weighted_score / (total_students * 8)) * 100
return performance_index
# Display Performance Index
pi = calculate_performance_index(grade_distribution)
print("\nPerformance Index (PI):", round(pi, 2), "%")
# Step 3: Identify Highest Scorer
highest_scorer = [Link][data['Best 5 percentage'].idxmax()]
print("\nHighest Scorer:\n", highest_scorer[['Name', 'Best 5 percentage']])
# Step 4: Calculate Subject-wise Grade Distribution (example for English)
subject = 'ENGLISH CORE' # Replace with other subjects as needed
def subject_grade_distribution(subject):
localhost:8888/notebooks/[Link]?kernel_name=python3 14/15
11/8/24, 1:13 AM Untitled2 - Jupyter Notebook
subject_grades = data[[subject]]
counts = {
'A1': len(subject_grades[subject_grades[subject] >= 90]),
'A2': len(subject_grades[(subject_grades[subject] >= 80) & (subject
'B1': len(subject_grades[(subject_grades[subject] >= 70) & (subject
'B2': len(subject_grades[(subject_grades[subject] >= 60) & (subject
'C1': len(subject_grades[(subject_grades[subject] >= 50) & (subject
'C2': len(subject_grades[(subject_grades[subject] >= 40) & (subject
'D': len(subject_grades[(subject_grades[subject] >= 33) & (subject_
'E': len(subject_grades[subject_grades[subject] < 33]),
}
return counts
# Display English Grade Distribution
english_distribution = subject_grade_distribution('ENGLISH CORE')
print("\nEnglish Grade Distribution:\n", english_distribution)
Grade Distribution:
{'A1': 2, 'A2': 8, 'B1': 15, 'B2': 9, 'C1': 2, 'C2': 0, 'D': 0, 'E': 0}
Performance Index (PI): 74.65 %
Highest Scorer:
Name MOHD NISSAR
Best 5 percentage 94.0
Name: 21, dtype: object
English Grade Distribution:
{'A1': 4, 'A2': 15, 'B1': 12, 'B2': 2, 'C1': 3, 'C2': 0, 'D': 0, 'E': 0}
In [ ]:
localhost:8888/notebooks/[Link]?kernel_name=python3 15/15