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>You can use first <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop_duplicates.html" rel="nofollow"><code>drop_duplicates</code></a> and then <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isin.html" rel="nofollow"><code>isin</code></a> or <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a>.</p>

<p>Python counts from <code>0</code>, so for same output add <code>1</code>.</p>

<pre><code>A = pd.DataFrame({'c':['a','b']})
B = pd.DataFrame({'c':['c','c','b','b','c','b','a','a']})


B = B.drop_duplicates('c')
print (B)
   c
0  c
2  b
6  a

print (B[B.c.isin(A.c)])
   c
2  b
6  a

print (B[B.c.isin(A.c)].index)
Int64Index([2, 6], dtype='int64')
</code></pre>

<hr>

<pre><code>print (pd.merge(B.reset_index(), A))
   index  c
0      2  b
1      6  a

print (pd.merge(B.reset_index(), A)['index'])
0    2
1    6
Name: index, dtype: int64
</code></pre>

python pandas indexing match