I want to select some specific rows based on two column values. For instance:
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 df Out: 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 strings based on the values โโof "user" and "item". Given a 2d numpy array that stores [user, item] value 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 result:
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 goal is to get a 2d numpy array that stores all the column values โโexcept for the element and user, which:
Out: array([[9, 4, 4], [17, 6, 5], [17, 6, 5], [16, 5, 5]])
As we can see, these are the values โโof the columns f1, f2, f3.
How can i do this?