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: 1) calculates the average temperature in countries (average av_temp by decade column grouped by country) 2) build a list of the 20 coldest countries in ascending av_temp order

import pandas import numpy as np df = pandas.DataFrame({'date': ['2013-05-01', '2013-06-01', '2013-07-01', '2013-08-01'], 'av_temp': [19.059, 17.613, 17.0, 19.759], 'deviations': [1.022, 0.473, 0.453, 0.717], 'country': ['Zimbabwe', 'Zimbabwe', 'Zimbabwe', 'Zimbabwe'], 'year': [2013, 2013, 2013, 2013], 'decade': ['2010-2020', '2010-2020', '2010-2020', '2010-2020']}) df

Questions about programming?Chat with your personal AI assistant