My dataframe looks like given below
col1 col2
type1 ['A','C','B','D']
type1 ['C','A','F','E']
type1 ['F','E','G','H']
type2 ['A','E','F','G']
type2 ['A','E','J','K']
I have to find out the elements from the list in col2 that are frequently appearing to a given user input. For example, if the user input is A. Then we have to find the top 3 elements that appear with A. And this has to be calculated for each value in col1. i.e
type1 - most frequent element for A - A,C will be the output
type2 - most frequent element for A - A,E will be the output
The data posted here is sample data.