My data frame looks like this:
+------+------+------+-----------+
| val1 | val2 | val3 | col1 |
+------+------+------+-----------+
| 3 | 1 | 1 | something |
| 4 | 2 | 1 | sth else |
| 2 | 2 | 3 | something |
| 3 | 1 | 1 | sth else |
| 2 | 2 | 1 | something |
+------+------+------+-----------+
I want to insert values into 3 different columns if they meet a condition (mask).
For the first 2 columns it works, so inserting usual strings is fine. How do I insert the product of multiple values from other columns of the same row.
So this does work for Issue and Type but Value does not work:
mask = (df.col1 == 'something')
df[['Issue','Type','Value']] = np.where( mask[:, None], ['sth','One', str(np.prod(df.iloc[:, 0:3], axis=1))], ['','',''])
In this case I want to insert the multiplication of val1, val2 and val3 within the same row as string into Value.
Desired output:
+------+------+------+-----------+-------+------+-------+
| val1 | val2 | val3 | col1 | Issue | Type | Value |
+------+------+------+-----------+-------+------+-------+
| 3 | 1 | 1 | something | sth | One | 3 |
| 4 | 2 | 1 | sth else | | | |
| 2 | 2 | 3 | something | sth | One | 12 |
| 3 | 1 | 1 | sth else | | | |
| 2 | 2 | 1 | something | sth | One | 4 |
+------+------+------+-----------+-------+------+-------+
PS.: Sorry about the headline, difficult to describe shortly.