I have a challenge in a pandas dataframe. Basically, I have 2 columns. In the first one, I have 3 different classes and in the second a list of students that are enrolled in the subject. The example is as follow:
df = pd.DataFrame({'Class': ['1A', '2B', '2C'],
'Students': [['Alice', 'Philips', 'John'],
['Philips', 'John', 'Anna', 'William'],
['Arthur', 'Alice', 'Anna', 'William']]
})
I would like to have a second dataframe with the number of students that are presented in more thant one class. In other words, the intersection between the classes, as follow
result= pd.DataFrame({'Comparison': ['1A-2B','1A-2C', '2B-2C'],
'Intersection size': [2, 1, 2]})
Thank you for your help and attention!