0

I want to change below dataframe to dataframe that remarks some pairs like this: Is that possible? if so, could you share how I can make this or which concept do I need to find.

Thanks in advance

From :

x    a    b    c    d    e    f    g   label
1  1.0  0.0  0.0  0.0  0.0  0.0  0.0     0.0
2  0.0  0.0  0.0  0.0  0.0  1.0  0.0     0.0
3  0.0  0.0  0.0  1.0  0.0  0.0  1.0     1.0

To :

x tag label
1  a    0.0
2  f    0.0
3  d    1.0
puhuk
  • 464
  • 5
  • 15

1 Answers1

0

Using concat with idxmax:

print (pd.concat([df["x"],df.iloc[:,1:-1].idxmax(axis=1),df["label"]],axis=1))

#
   x  0  label
0  1  a    0.0
1  2  f    0.0
2  3  d    1.0
Henry Yik
  • 22,275
  • 4
  • 18
  • 40