I have a matrix like below and I need to create 2 more columns with minimum value from columns COL01-04 and name of that column (exluding NaN):
In[1]: matrix
Out[1]:
ID COL01 COL02 COL03 COL04
0 0001 NaN 1662 1583 1697.4
1 0002 NaN 1006 1476 1018.44
2 0003 1452 1487 2197.5 1516.27
3 0004 NaN 1554 2298 1585.62
like this:
ID COL01 COL02 COL03 COL04 Min_val Min_col
0 0001 NaN 1662 1583 1697.4 1583 COL03
1 0002 NaN 1006 1476 1018.44 1006 COL02
2 0003 1452 1487 2197.5 1516.27 1452 COL01
3 0004 NaN 1554 2298 1585.62 1554 COL02
I've already tried
for i in range(0, len(matrix)):
matrix['Min_val'] = matrix[['COL01', 'COL02', 'COL03', 'COL04']].min()
but the result is NaN everywhere, type numpy.float64.
NaNeverywhere.