I have a pandas dataframe "df" having columns[Country,Region,Happiness Score,Year]
.
There are total 165
countries in df having data for 3 years(2015,2016,2017)
, therefore length of df is 165*3=495
.
There are total 10
unique regions in df and each country has its region name in 'Region' column.
I want to produce an output showing country having minimum and maximum happiness score for each unique region.
For example, output should have columns like [Region,Min Happiness Score,Max Happiness Score,Country
having min Happiness Score for that region,Country having max Happiness Score for that region].
Since there are 10 unique regions, it is obvious that output should also have length 10. Solutions using pandas functions and pandasql both are welcome but I would prefer using solutions with pandas functions.