Need to create a new column that concatenate multiple columns based on the value of each column. For example, input:
s1 s2 s3
1 0 0
1 1 0
0 1 2
Output:
s1 s2 s3 col
1 0 0 s1
1 1 0 s1, s2
0 1 2 s2, s3
Basically I need to output a column name when the value is >0, and only output it once even if the number is more than 1.
The code I used but didn't work:
df['col'] = 's1' * min(df['s1'], 1) + ', ' + 's2' * min(df['s2'], 1) + ', ' + 's3' * min(df['s3'], 1)