For each row in the pandas dataframe I want to find the cell/cells with the minimum value and return its row and column name separately. I also want to check if that minimum value is less than one.
E.g.,
NAMES, Oil, Fat, Salt
Salad, 0.2, 0.1, 0.8
Bread, 0.1, 0.9, 0.1
Rice, 1, 1, 1
Output of the above dataframe:
['Salad', 'Fat']
[['Bread', 'Oil'], ['Bread', 'Salt']]
<No output because the minimum is not less than 1>
My current code looks like follows,
pairs = df.set_index('NAMES').apply(lambda row: [[row.name, l] for l in row[row == row.min()].index], axis=1).values.tolist()
Please help me.