You can use apply
:
print (B.groupby('b')['MOST_FREQUENT'].apply(lambda x: x.mode())
.reset_index(level=1, drop=True).reset_index())
b MOST_FREQUENT
0 I 2
1 II 1
Another solution is use SeriesGroupBy.value_counts and return first index
value, because value_counts
sorts values:
print (B.groupby('b')['MOST_FREQUENT'].apply(lambda x: x.value_counts().index[0])
.reset_index())
b MOST_FREQUENT
0 I 2
1 II 1
EDIT: You can use most_common
from collections import Counter
print (B.groupby(['b']).agg(lambda x: Counter(x).most_common(1)[0][0]).reset_index())
b MOST_FREQUENT
0 I 2
1 II 1