Generation

generate functionWed, 01 Feb 2023

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 Add it to output all 66 lines of the dataframe

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) print(dfp_copy) return dfp_copy

Questions about programming?Chat with your personal AI assistant