Calculating index for projects
I am working on a Python project for my portfolio, It is allocating projects to students. For this, I am importing data from a file "student_Record.csv". The file has the student's name, last name, marks and 3 project preferences. I want to assign an index to each project before I assign the projects to the students. The index is calculated as Index(P)=50*(Number of Students that put P as 1st preference) + 25*(Number of students that put P as 2nd preference) + 1*(Number of students that put P as 3rd preference)
The sample data in the file looks like Sample data
I have done the following:
import pandas as pd
df = pd.read_csv('sample_data.csv')
project_preferences = {}
for index, row in df.iterrows():
# Get the student's preferences
preferences = [row['Pref_1'], row['Pref_2'], row['Pref_3']]
# Assign preference weights to projects
for preference in preferences:
project = int(preference)
# Update the project's preference count
if project not in project_preferences:
project_preferences[project] = [0, 0, 0]
project_preferences[project][preferences.index(preference)] += 1
# Calculate Wayne index for each project
wayne_index = {}
for project, preferences in project_preferences.items():
wayne_index[project] = 50 * preferences[0] + 25 * preferences[1] + preferences[2]
# Print the Wayne index for each project
for project, index in wayne_index.items():
print(f"Wayne index for Project {project}: {index}")
Am I doing it right?
Comments
Post a Comment