I have a df that looks like the following:
candidate; partyList; shareOfVotes; outcome
A list1 0.11 elected
B list1 0.10 elected
C list1 0.09 not-elected
D list2 0.22 elected
E list2 0.15 not-elected
F list2 0.02 not-elected
I want to create a new df that contains only the last elected and the first non-elected candidate for each candidate list. The only way to know if a candidate was elected is by checking the column "outcome". So, I believe the best way to do this would be to select the candidate with the lowest share of the votes among the elected ones, and the candidate with the highest share of the votes among the non-elected ones for each party list. The new df should look like this:
candidate; partyList; shareOfVotes; outcome
B list1 0.10 elected
C list1 0.09 not-elected
D list2 0.22 elected
E list2 0.15 not-elected
The df has several other columns with characteristics of the candidates that I want to keep. Thanks in advance to anyone who can help me.