i want to find the top n values in a row of a dataframe.
Practical example:
data = {'First': [1, 2,3],
'Second': [2,1,5],
'Third': [5,1,2]
}
df = pd.DataFrame (data, columns = ['First','Second','Third'])
First Second Third
0 1 2 5
1 2 1 3
2 3 5 2
I want to iterate through each row and select the top n values. In this example the top 2 and replace the values with 1 and all others with 0.
So my desired output would look like:
First Second Third
0 0 1 1
1 1 0 1
2 1 1 0