I am new to pandas library and I would appreciate your help. This is my input
| ID | DATE | LABEL | STOCK |
|---|---|---|---|
| AA | 01/26/2020 | TRUE | 100 |
| AA | 01/27/2020 | FALSE | 200 |
| BB | 01/28/2020 | FALSE | 300 |
| BB | 01/29/2020 | TRUE | 500 |
| BB | 01/30/2020 | FALSE | 100 |
| CC | 01/26/2020 | TRUE | 200 |
| CC | 01/27/2020 | FALSE | 300 |
| CC | 01/28/2020 | FALSE | 100 |
| CC | 01/29/2020 | TRUE | 400 |
I would like to look at the Label column and for the first "TRUE" label that is found for each ID I need to copy the value of stock in a new column. If an ID has more than one TRUE I need to consider only the first one.
Here is the output i want to obtain:
| ID | DATE | LABEL | STOCK | NEW |
|---|---|---|---|---|
| AA | 01/26/2020 | TRUE | 100 | 100 |
| AA | 01/27/2020 | FALSE | 200 | |
| BB | 01/28/2020 | FALSE | 300 | |
| BB | 01/29/2020 | TRUE | 500 | 500 |
| BB | 01/30/2020 | FALSE | 100 | |
| CC | 01/26/2020 | TRUE | 200 | 200 |
| CC | 01/27/2020 | FALSE | 300 | |
| CC | 01/28/2020 | FALSE | 100 | |
| CC | 01/29/2020 | TRUE | 400 |
Thank you for your help!