I have a pandas df that looks like the below:
Current df:
| Case | Task | Text_Present |
|---|---|---|
| 123 | Yes | |
| 123 | Outreach | No |
| 456 | Session | No |
| 456 | No |
I would like to drop duplicate cases, but based on a condition of the Text_Present field.
If there's a 'Yes' present, keep the record where 'Yes' is present. If there's no 'Yes' present (ex: Case 456), then keep one of the records for 456 - does not matter which one.
I'm basically looking to understand the % Yes to % No, but the math is off due to the fact that the cases are duplicated as a result of the Description field - since I want to count any case where there was a 'Yes' in any Task as just a 'Yes' overall for that case.
My goal output is:
| Case | Task | Text_Present |
|---|---|---|
| 123 | Yes | |
| 456 | Session | No |
Ultimately, I want to compare % Yes to % No in a simple barchart, but the duplication is resulting in inaccurate percentages.
As far as I can tell, df.drop only offers first and last.
Thanks All!