How to find column values which contains unique value in another column from same dataframe?
<p>I have a dataframe: </p>

<pre><code>  Id  name  value
0 1   aaa   x
1 2   aaa   y
2 3   aaa   z
3 4   ddd   t
4 5   ddd   t
5 6   fff   j
6 7   ggg   m
7 8   ggg   n
</code></pre>

<p>I want to find only those rows whose names are duplicate and for these duplicate rows the values are different.</p>

<p><strong>Expected output :</strong> </p>

<pre><code>  Id name  value
 0 1   aaa   x
 1 2   aaa   y
 2 3   aaa   z
 3 7   ggg   m
 4 8   ggg   n
</code></pre>

<p>I'm trying with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow">groupby</a>:</p>

<pre><code>df.groupby('name')
</code></pre>

<p>Is this groupby function usefull for this task? How I can achieve what I want exactly?</p>

<p>This line of code will count the number of values by name:</p>

<pre><code>df.groupby('name')['value'].transform(pd.Series.nunique)
Out[8]: 
0    3
1    3
2    3
3    1
4    1
5    1
6    2
7    2
</code></pre>

<p>Note that I use <code>.transform(pd.Series.nunique)</code> rather than simply <code>.nunique()</code> on the <code>groupby</code> object. This way, the result will be of the same length as the original dataframe, and you can use it directly for filtering:</p>

<pre><code>df[df.groupby('name')['value'].transform(pd.Series.nunique) &gt; 1]
Out[9]: 
   Id name value
0   1  aaa     x
1   2  aaa     y
2   3  aaa     z
6   7  ggg     m
7   8  ggg     n
</code></pre>

python pandas dataframe