Digital resources in the Social Sciences and Humanities OpenEdition Our platforms OpenEdition Books OpenEdition Journals Hypotheses Calenda Libraries OpenEdition Freemium Follow us

Everyday coding II: randomising groups while respecting preferences

Most academics are not only researchers but also teachers and administrators. Teaching and administration are tasks which often come together and pose (mathematical) problems that scripts may be able to handle for us.

Acting from necessity, I have started my “everyday coding” series and propose script-based solutions for some common administrative problems. The second edition of “everyday coding” addresses the issue of student-supervisor matching. If you do not want to leave finding a supervisor for BA and MA theses entirely up to students, you might want to combine group randomisation with some form of preference indication. Randomising groups itself is an easy task to perform with ready-made online tools. But if the groups have different sizes and if students can indicate a certain amount of preferred groups beforehand, the problem gets too complicated for freely-available software to handle.

This is why I have decided to write a script in Python. In my use case, each supervisor accepts between one and six students, and each student can indicate between one and four preferences by adding their name to a specific column in a spreadsheet. These preferences are not ranked.

The input spreadsheet, therefore, has the following columns:

  • one column called “names” (containing names of teachers)
  • two columns with theories and methods that match the teachers’ expertise
  • one column called “student” where students can enter their names in up to four cells

As every student submits an individual spreadsheet, all input files must be merged to analyse the indicated preferences. Also, the information in the input spreadsheets has to be linked with information in a different spreadsheet which indicates how many students each teacher can supervise. As this information may change throughout the matching process, it should not be visible to the student and is therefore not included in the spreadsheets that the students use.

The file for teachers only thus includes the column “No. of theses” and other internal information on the teachers’ affiliation and qualifications.

The best way to “merge” and compare data from several spreadsheets in Python is to use the pandas package and read all the data into so-called DataFrames.

In my Python script, I have combined the information from the teachers-only file with the many “student” columns coming from the preferences spreadsheets. As all those spreadsheets have the same column headings, multiple new columns with the same name “student” had to be transformed into a sequence of columns named “Student”, “Student.1”, “Student.2” etc.

The draft script looks like this:

CreateRandomGroups_withPreferences.py

It performs the following tasks:

  • reading all files and creating a joint DataFrame
  • identification of all teachers
  • identification of all students
  • identification of the student-teacher combinations with the least competition
  • matching each teacher with “n” number of students who have indicated a preference for their group, starting with teachers for whom the lowest number of students have applied
  • students already matched are excluded from each new iteration
  • exception handling if the number of students is smaller than the number of students that a teacher can supervise
  • display of names of students who could not be matched with any preferred teacher
  • define how many students without a preferred teacher are acceptable, and re-run the script to find the matches which allow the greatest number of students possible to work with a preferred teacher

If you have any ideas for improving the code, I look forward to your comments. One issue to tackle in the future could be a rule-based selection of second readers from the existing pool of teachers. Also, I would like to thank Stack Overflow user AKX for the idea of combining randomisation with a fitness test.


OpenEdition suggests that you cite this post as follows:
Monika Barget (January 10, 2023). Everyday coding II: randomising groups while respecting preferences. INSULAE. Retrieved November 4, 2024 from https://doi.org/10.58079/qd97


Monika Barget

Monika Barget is an assistant professor in History at Maastricht University and co-coordinator of the DigiKAR geohumanities project at IEG Mainz. Her research interests include spatial history, digital mapping, political history and media.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.