1

I am trying to make the following transformation in python

from

   A  B  C  D  E  
   x  1  0  0  0 
   y  0  1  1  0 
   z  1  0  0  1 

to

   x  B 
   y  C,D
   z  A,E

Do you have any ideas ?

Fortino
  • 11
  • 2

1 Answers1

1

Check with dot

df=df.set_index('A')
df.dot(df.columns+',').str[:-1]
A
x      B
y    C,D
z    B,E
dtype: object
BENY
  • 317,841
  • 20
  • 164
  • 234