Python equivalence of R's match() for indexing
<p>So i essentially want to implement the equivalent of R's match() function in Python, using Pandas dataframes - without using a for-loop. </p>

<p>In R match() returns a vector of the positions of (first) matches of its first argument in its second. </p>

<p>Let's say that I have two df A and B, of which both include the column C. Where </p>

<pre><code>A$C = c('a','b')
B$C = c('c','c','b','b','c','b','a','a')
</code></pre>

<p>In R we would get</p>

<pre><code>match(A$C,B$C) = c(7,3)
</code></pre>

<p>What is an equivalent method in Python for columns in pandas data frames, that doesn't require looping through the values.</p>

<p>This gives all the indices that are matched (with python's 0 based indexing):</p>

<pre><code>import pandas as pd

df1 = pd.DataFrame({'C': ['a','b']})
print df1

   C
0  a
1  b

df2 = pd.DataFrame({'C': ['c','c','b','b','c','b','a','a']})
print df2   

   C
0  c
1  c
2  b
3  b
4  c
5  b
6  a
7  a

match = df2['C'].isin(df1['C'])
print [i for i in range(match.shape[0]) if match[i]]

#[2, 3, 5, 6, 7]
</code></pre>

python pandas indexing match