There is a Python and Pandas function. def year_leaders(dfp): dfp_copy = dfp.copy() dfp_copy.sort_values(by=['chart_debut','num_of_hits'], ascending=False, inplace=True) dfp_copy.drop_duplicates(subset='chart_debut', keep='first', inplace=True) dfp_copy.set_index('chart_debut', inplace=True) return dfp_copy year_leaders(dfp) Modify it to output all 66 lines of the dataframe
def year_leaders_all(dfp): dfp_copy = dfp.copy() dfp_copy.sort_values(by=['chart_debut','num_of_hits'], ascending=False, inplace=True) dfp_copy.drop_duplicates(subset='chart_debut', keep='first', inplace=True) return dfp_copy year_leaders_all(dfp)