Dec-02-2017, 12:26 PM
Hi
I have a dataframe that looks like this:
index - column - score
1 4 0.75
2 2 0.75
3 3 1
4 1 0.75
5 5 1
thanks!
I have a dataframe that looks like this:
Output: 1 2 4 5 3
1 0.25 0 0.75 0 0
2 0 0.75 0 0 0
4 0.75 0 0.25 0 0
5 0 0 0 1 0
3 0 0 0 0 1
Now i want to know for each index which column contains the highest score and the corresponding score. def matchResult(): match = df.max(axis=1) # shows the highest score match1 = df.idxmax(axis=1) # shows the column containing the highest score print(match) print(match1)
Output:1 0.75
2 0.75
4 0.75
5 1.00
3 1.00
dtype: float64
1 4
2 2
4 1
5 5
3 3
dtype: object
Does anybody know how I can combine them, so I get one output looking like:index - column - score
1 4 0.75
2 2 0.75
3 3 1
4 1 0.75
5 5 1
thanks!