I have a problem with slicing data with pandas with multiindex with repetation.
Let's say I have a table (A and B are indicies)
A B C
1 1 11
1 2 12
1 3 13
2 1 21
2 2 22
2 3 23
and so on
And to vectors
a = [1, 2, 3, 1, 2, 1, 2 ]
b = [3, 2, 1, 3, 2, 1, 3 ]
I'd like to slice the table in a way to return vector c with values in line with indicies from vectors a and b.
c = [13, 22, 31, 13, 22, 11, 23]
Only thing that comes to my mind is to pivot this table and get:
A B1 B2 B3
1 11 12 13
2 21 22 23
3 31 32 33
The apply one index to column A through loc to get proper rows, multiply with indicator matrix for chosing proper column for each row and cumsum to get a vector (with another slicing). I'm sure that there must be easier way to do it but I cannot find the proper way to do it