I have a dataframe similar to the following:
data = {'ref': ['0001', '0002', '0003', '0004', '0005', '0006', '0007'],
'topic': [-1, 0, 1, 2, 0, -1, 2],
'-1': [1, 0, 0, 0.1, 0, 0.99, 0],
'0': [0, 1, 0, 0, 1, 0, 0.1],
'1': [0, 0, 0.99, 0, 0, 0, 0],
'2': [0.4, 0, 0, 0.7, 0, 0, 1],
}
df = pd.DataFrame(data)
If the column topic value is -1, then I want to look in the same row of columns 0 to 2, and change the value in topic, to the header of the max value.
As an example, in the first row in the table above, the column topic has a value of -1, so I want to change that value to whatever is the header name of the max value in the row. So that would be column 2, which has a value of 0.4.
So now the table looks like this, where the topic value of ref 0001 has changed from -1 to 2
The other point is, that if like ref 0006, there is no value > 0 in the other columns despite having a topic value of -1, then it should be left alone.
I hope this makes sense. Struggling hard to get this done.
Thank you!

