1

I am trying to get the column index for the lowest value in a row. For example, I have the dataframe

              0            1        Min. dist
0    765.180690   672.136265        672.136265            
1    512.437288   542.701564        512.437288   

and need the following output

              0            1        Min. dist       ColumnID
0    765.180690   672.136265        672.136265             1       
1    512.437288   542.701564        512.437288             0

I've gotten the Min. dist column by using the code df['Min. dist'] = df.min(axis=1)

Can anyone help with this? Thanks

nostres
  • 89
  • 1
  • 9

1 Answers1

2

Try using idxmin :

df['ColumnID']=df.idxmin(axis=1)
Raghav Gupta
  • 454
  • 3
  • 12