Pandas: Add Series to DataFrame ordered by column
<p>I am sure this was asked before, but I couldn't find it. I want to add a Series as a new column to the DataFrame. All the Series Index names are contained in one column of the DataFrame, but the Dataframe has more rows than the Series.</p>

<pre><code>DataFrame:
0 London 231
1 Beijing 328
12 New York 920
3 Singapore 1003

Series:
London AB
New York AC
Singapore B
</code></pre>

<p>and the result should look like</p>

<pre><code>0 London 231 AB
1 Beijing 328 NaN
12 New York 920 AC
3 Singapore 1003 B
</code></pre>

<p>How can I do this without loops? Thanks!</p>

<p>based on @Joe R solution with some modificaiton. say, df is your DataFrame and s is your Series</p>

<pre><code>s = s.to_frame().reset_index()
df = df.merge(s,how='left',left_on=df['B'],right_on=s['index']).ix[:,[0,1,3]]
</code></pre>

python pandas dataframe merge series