I would like to find the column of a data frame with the maximum value per row and if there are multiple equally large values, then return all the column names where those values are. I would like to store all of these values in the last column of the data frame. I have been referencing the following post, and am unsure of how to modify it to handle data frames:
Using Python's max to return two equally large values
So if my data looked like this
Key Column_1 Column_2 Column_3
0 1 2 3
1 1 1 0
2 0 0 0
My goal is an output that looks like this:
Key Column_1 Column_2 Column_3 Column_4
0 1 2 3 Column_3
1 1 1 0 Column_1,Column_2
2 0 0 0 NA
I know how to use idxmax(axis=1,skipna = True) to return the first max and know that if I change 0 to Nan in the dataframe it will populate the last row correctly, just not sure how to do this when there are multiple max values.
Any help is greatly appreciated ! I am an R programmer and this is my first time in Python.