how to use columns values to groupby
问题 I need to get the top1 and top2 rating watched by 'ma' and 'young'. here I only need to specifically define my value but not column usinga group by. data: gender age rating ma young PG fe young PG ma adult PG fe adult PG ma young PG fe young PG ma adult R fe adult R ma young R fe young R code : top1 = df.groupby(['ma','young']])['rating'].apply(lambda x: x.value_counts().index[0]) top2 = df.groupby(['ma','young']])['rating'].apply(lambda x: x.value_counts().index[1]) Please let me know how do