I would like to get 3 cities with the biggest "raised" value for each state based on the dataframe below.
So, there is a number of campaigns for each city. I want to sum up "raised" amounts for each of the cities, to get a total raised amount for each city, and then to display three top cities cities in terms of the "raised" amount for each state.
category city created goal name raised state url
0 Medical OXNARD December 30, 2018 15000.0 Wayne's Cancer Care Fund 80.0 CA https://www.gofundme.com/8qz8h6-waynes-cancer-...
1 Medical CHINO HILLS December 4, 2018 2000.0 Mother of two has cancer and needs help 500.0 CA https://www.gofundme.com/3qi0rog
2 Medical BATTLE CREEK December 6, 2018 10000.0 Hospital costs 570.0 MI https://www.gofundme.com/3sbwals
3 Medical FEASTERVILLE TREVOSE December 3, 2018 10000.0 Help raise Joey & Brianna 2200.0 MI https://www.gofundme.com/get-away-from-him
4 Medical WEST PALM BEACH December 12, 2018 6000.0 Kelvin McCray Recovery Fund 2450.0 MI https://www.gofundme.com/send-ricky-to-school
5 Medical JONES December 11, 2018 25000.0 Wheelchair Accessible Vehicle for Taelor 2270.0 OK https://www.gofundme.com/HelpTaelorTransport
6 Medical CONROE December 20, 2018 10000.0 "A Good friend in dire need" 1250.0 OK https://www.gofundme.com/4dmeoko
Sample date in json:
[{
"category": "Medical",
"city": "OXNARD",
"created": "December 30, 2018",
"goal": 15000.0,
"name": "Wayne's Cancer Care Fund",
"raised": 80.0,
"state": "CA",
"url": "https://www.gofundme.com/8qz8h6-waynes-cancer-care-fund"
},
{
"category": "Medical",
"city": "CHINO HILLS",
"created": "December 4, 2018",
"goal": 2000.0,
"name": "Mother of two has cancer and needs help",
"raised": 500.0,
"state": "CA",
"url": "https://www.gofundme.com/3qi0rog"
},
{
"category": "Medical",
"city": "BATTLE CREEK",
"created": "December 6, 2018",
"goal": 10000.0,
"name": "Hospital costs",
"raised": 570.0,
"state": "MI",
"url": "https://www.gofundme.com/3sbwals"
},
{
"category": "Medical",
"city": "FEASTERVILLE TREVOSE",
"created": "December 3, 2018",
"goal": 10000.0,
"name": "Help raise Joey & Brianna",
"raised": 2200.0,
"state": "MI",
"url": "https://www.gofundme.com/get-away-from-him"
},
{
"category": "Medical",
"city": "WEST PALM BEACH",
"created": "December 12, 2018",
"goal": 6000.0,
"name": "Kelvin McCray Recovery Fund",
"raised": 2450.0,
"state": "MI",
"url": "https://www.gofundme.com/send-ricky-to-school"
},
{
"category": "Medical",
"city": "JONES",
"created": "December 11, 2018",
"goal": 25000.0,
"name": "Wheelchair Accessible Vehicle for Taelor",
"raised": 2270.0,
"state": "OK",
"url": "https://www.gofundme.com/HelpTaelorTransport"
},
{
"category": "Medical",
"city": "CONROE",
"created": "December 20, 2018",
"goal": 10000.0,
"name": "\"A Good friend in dire need\"",
"raised": 1250.0,
"state": "OK",
"url": "https://www.gofundme.com/4dmeoko"
}]
The expected outcome should look like this:
123 State1 City1 100
3 City2 99
58 City3 98
8 State2 City4 97
12 City5 96
1 City6 95
this doesn't really help:
maxRaisedCityByState = a.df.groupby(['state','city'])['raised'].max()
The answers from the allegedly duplicate question do not help:
- https://stackoverflow.com/a/20069379/5286299 - does not work, because I need only city, state, raised and goal columns to be displayed, also I need them to be sorted by state and within the state by raised.
- https://stackoverflow.com/a/32397818/5286299 - does not work, because I also have to see the city