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!