I am trying to filter out rows within a group based on the string value of the ApplicationStatus field. Here's the table:
| Primary Application | Total Request | ApplicationStatus |
|---|---|---|
| Application 1 | 10,000 | Approved |
| Application 1 | 10,000 | Declined |
| Application 2 | 15,000 | Approved |
| Application 2 | 30,000 | Declined |
| Application 3 | 50,000 | Declined |
| Application 3 | 20,000 | Locked |
I've been trying to write a function that, if row 1 is "Approved," then delete the second row of the group, and if row 1 is "Declined," then delete the first row of the group. Here's my expected output:
| Primary Application | Total Request | ApplicationStatus |
|---|---|---|
| Application 1 | 10,000 | Approved |
| Application 2 | 15,000 | Approved |
| Application 3 | 20,000 | Locked |
Here's my attempted code:
df_Group = df.groupby("Primary Application").apply(lambda x: x.loc[0] if x.ApplicationStatus == 'Approved' else x.loc[1])