I wish to select some specific rows based on two column values. For example:
d = {'user' : [1., 2., 3., 4] ,'item' : [5., 6., 7., 8.],'f1' : [9., 16., 17., 18.], 'f2':[4,5,6,5], 'f3':[4,5,5,8]}
df = pd.DataFrame(d)
print dfOut:f1 f2 f3 item user
0 9 4 4 5 1
1 16 5 5 6 2
2 17 6 5 7 3
3 18 5 8 8 4
I want to select the rows based on the values of 'user' and 'item'. Given an 2d numpy array which stores the [user, item] values pairs:
samples = np.array([[1,5],[3,7],[3,7],[2,6]])
Out:
array([[1, 5],[3, 7],[3, 7],[2, 6]])
Then the expected output is:
Out:f1 f2 f3 item user
0 9 4 4 5 1
2 17 6 5 7 3
2 17 6 5 7 3
1 16 5 5 6 2
Then, my final objective is to get an 2d numpy array stores all the columns values except item and user, which is:
Out:
array([[9, 4, 4],[17, 6, 5],[17, 6, 5],[16, 5, 5]])
As we can see, it is the values of columns f1, f2, f3.
How can I do this?