pandas - Merging on string columns not working (bug?) : <p>I'm trying to do a simple merge between two dataframes. These come from two different SQL tables, where the joining keys are strings:</p>

<pre><code>&gt;&gt;&gt; df1.col1.dtype
dtype('O')
&gt;&gt;&gt; df2.col2.dtype
dtype('O')
</code></pre>

<p>I try to merge them using this:</p>

<pre><code>&gt;&gt;&gt; merge_res = pd.merge(df1, df2, left_on='col1', right_on='col2')
</code></pre>

<p>The result of the inner join is empty, which first prompted me that there might not be any entries in the intersection:</p>

<pre><code>&gt;&gt;&gt; merge_res.shape
(0, 19)
</code></pre>

<p>But when I try to match a single element, I see this really odd behavior.</p>

<pre><code># Pick random element in second dataframe
&gt;&gt;&gt; df2.iloc[5,:].col2
'95498208100000'

# Manually look for it in the first dataframe
&gt;&gt;&gt; df1[df1.col1 == '95498208100000']
0 rows × 19 columns
# Empty, which makes sense given the above merge result

# Now look for the same value as an integer
&gt;&gt;&gt; df1[df1.col1 == 95498208100000]
1 rows × 19 columns
# FINDS THE ELEMENT!?!
</code></pre>

<p>So, the columns are defined with the 'object' dtype. Searching for them as strings don't yield any results. Searching for them as integers does return a result, and I think this is the reason why the merge doesn't work above..</p>

<p>Any ideas what's going on?</p>

<p>It's almost as thought Pandas converts <code>df1.col1</code> to an integer just because it can, even though it <em>should</em> be treated as a string while matching. </p>

<p>(I tried to replicate this using sample dataframes, but for small examples, I don't see this behavior. Any suggestions on how I can find a more descriptive example would be appreciated as well.)</p>
