So I have two pandas frames, A and B.
A - 1000 rows of 500 columns filled with binary values indicating either presence or absence.
B is 1024 rows x 10 columns and represents a complete iteration of 0 and 1, therefore it has 1024 rows.
I am trying to find which rows in in the specific 10 columns of A correspond to a given row in B. I need the whole row to match, not element by element.
For example, I would like
A[(A.ix[:,(1,2,3,4,5,6,7,8,9,10)==(1,0,1,0,1,0,0,1,0,0)).all(axis=1)]
To return that the rows (3,5,8,11,15)in coincide with that row (1,0,1,0,1,0,0,1,0,0)B in these specific columns(1,2,3,4,5,6,7,8,9,10)
And I want to do this on every line in B. The best way I could do was this:
import numpy as np
for i in B:
B_array = np.array(i)
Matching_Rows = A[(A.ix[:,(1,2,3,4,5,6,7,8,9,10)] == B_array).all(axis=1)]
Matching_Rows_Index = Matching_Rows.index
, while, 20 000 ; .
DataFrame.apply . ?
, - - , python.
!