Generation

generate functionMon, 06 Feb 2023

There is a df Pandas dataframe: date av_temp deviations country year decade 577457 2013-05-01 19.059 1.022 Zimbabwe 2013 2010-2020 577458 2013-06-01 17.613 0.473 Zimbabwe 2013 2010-2020 577459 2013-07-01 17.000 0.453 Zimbabwe 2013 2010-2020 577460 2013-08-01 19.759 0.717 Zimbabwe 2013 2010-2020 Write a function that shows the top 20 rows from the country column sorted by av_temp values in descending order.

def top(df, column_name): return df.sort_values(by=column_name, ascending=False)[:20] top(df, 'av_temp')

Questions about programming?Chat with your personal AI assistant