I want to find the minimum value per row and create a new column indicating which of those columns has the lowest number. Unfortunately, it seems like pandas isn't immediately able to help in this regard. My research has led to the min() function, which does find the lowest for each row (when axis=1), but there's no further information beyond the number itself.
initialDict = {"A":[6.53,11.47,92.08],"B":[9.11,8.15,12.49]}
initialDf = pd.DataFrame.from_dict(initialDict,orient="index",columns=["Value 1","Value 2","Value 3"])
>>> initialDf
Value 1 Value 2 Value 3
A 6.53 11.47 92.08
B 9.11 8.15 12.49
>>> initialDf.min(axis=1,numeric_only=True)
A 6.53 # Value 1 - just a number is useless to me.
B 8.15 # Value 2 - how do i access which columns these are?
My sample data is a lot larger than two rows, so ideally I'd want a vectorised solution.
Can I somehow access which column has the lowest number per row and assign it to a new value?