samedi 23 juillet 2016

How can you find the most common sets using python?

I have a pandas dataframe where one column is a list of all courses taken by a student. The index is the student's ID.

I'd like to find the most common set of courses across all students. For instance, if the dataframe looks like this:

ID    |     Courses
1           [A, C]
2           [A, C]
3           [A, C] 
4           [B, C]
5           [B, C]
6           [K, D] 
...

Then I'd like the output to return the most common sets and their frequency, something like:

{[A,C]: 3, [B,C]: 2}

Aucun commentaire:

Enregistrer un commentaire