How to find rows that differ by only one column in pandas?
<p>I have a dataframe, with three columns. I have grouped them based on two of the 3 columns. Now I need to find only those rows where the two columns <code>word1,word2</code> are same but the column <code>Tag</code>,the third column, is different.</p>

<p>This something like I need to find those columns, where for the same <code>word1 and word2</code> we have different labels. But I am not able to filter the dataFrame based on the groupby construct shown below</p>

<pre><code>newComps.groupby(['word1','word2']).count()
</code></pre>

<p><a href="http://i.stack.imgur.com/A804L.png" rel="nofollow"><img src="http://i.stack.imgur.com/A804L.png" alt="enter image description here"></a></p>

<p>Here it wil lbe helpful if I can see only the ones with same word1,word2 but with a different Tag, rather than all the entries. I have tried with calling the above code inside <code>[]</code>, as we use to filter the data, but to no avail</p>

<p>Ideally I should see only </p>

<pre><code>A,gawam, A1
A,gawam,BS1
A,gawaH, T1
A, gawaH, T2
</code></pre>

<p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop_duplicates.html" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.drop_duplicates.html</a></p>

<p>look at the <code>subset</code> and the <code>keep</code> option</p>

python pandas