| P | T1 | T2 | T3 |
|---|---|---|---|
| 0 | 1 | 2 | 3 |
| 1 | 1 | 2 | 0 |
| 2 | 3 | 1 | 2 |
| 3 | 1 | 0 | 2 |
In the above pandas dataframe df, I want to add columns on the basis of the value of column 'P'.
if df['P'] == 0: 0
if df['P'] == 1: T1 (=1)
if df['P'] == 2: T1+T2 (=3+1=4)
if df['P'] == 3: T1+T2+T3 (=1+0+2=3)
In other words, I want to add from T1 to TN if df['P'] == N. How can I implement this with Python code?