Given a pandas dataframe like this:
df = pd.DataFrame([['A', 'M1', 1], ['A', 'M2', 4],
['B', 'M1', 3], ['B', 'M2', 2],
['C', 'M1', 5], ['C', 'M2', 0]],
columns=['task', 'method', 'value'])
task method value
0 A M1 1
1 A M2 4
2 B M1 3
3 B M2 2
4 C M1 5
5 C M2 0
I want to generate a comparison table like this:
method M1 M2
method
M1 0 2
M2 1 0
That is, the value at row r
, column c
is the number of tasks for which method r
had a higher value than method c
.
I tried adapting the solution here, but I can't figure out how to take into account the task.
How can I go about doing creating this table?