Please assist with the below
import pandas as pd
df = pd.DataFrame({'Grp': [1,1,1,1,2,2,2,2,3,3,3,4,4,4], 'Org1': ['x','x','y','y','z','y','z','z','x','y','y','z','x','x'], 'Org2': ['a','a','b','b','c','b','c','c','a','b','b','c','a','a'], 'Value': [0,0,3,1,0,1,0,5,0,0,0,1,1,1]})
df
*** I need the first non zero value having "FLAG" = 1 and other 0
Details :
For each unique set of "Grp, Org1, Org2" and based on the "Value" "FLAG" to have 1 and the others as 0.
If values are all 0 in a Column then FLAG = 0 for all
If values are all NON ZERO in a Column then first instance to have FLAG = 1 and others 0
I am expecting the output as below
+----+-----+------+------+-------+------+
| | Grp | Org1 | Org2 | Value | FLAG |
+----+-----+------+------+-------+------+
| 0 | 1 | x | a | 0 | 0 |
| 1 | 1 | x | a | 0 | 0 |
| 2 | 1 | y | b | 3 | 1 |
| 3 | 1 | y | b | 1 | 0 |
| 4 | 2 | z | c | 0 | 0 |
| 5 | 2 | y | b | 1 | 1 |
| 6 | 2 | z | c | 0 | 0 |
| 7 | 2 | z | c | 5 | 1 |
| 8 | 3 | x | a | 0 | 0 |
| 9 | 3 | y | b | 0 | 0 |
| 10 | 3 | y | b | 0 | 0 |
| 11 | 4 | z | c | 1 | 1 |
| 12 | 4 | x | a | 1 | 1 |
| 13 | 4 | x | a | 1 | 0 |
+----+-----+------+------+-------+------+