Drop duplicates for rows with interchangeable name values (Pandas, Python)
<p>I have a DataFrame of form</p>

<pre><code>person1, person2, ..., someMetric
John, Steve, ..., 20
Peter, Larry, ..., 12
Steve, John, ..., 20
</code></pre>

<p>Rows 0 and 2 are interchangeable duplicates, so I'd want to drop the last row. I can't figure out how to do this in Pandas.</p>

<p>Thanks!</p>

<p>Here's a NumPy based solution  -</p>

<pre><code>df[~(np.triu(df.person1.values[:,None] == df.person2.values)).any(0)]
</code></pre>

<p>Sample run -</p>

<pre><code>In [123]: df
Out[123]: 
  person1 person2 someMetric
0    John   Steve         20
1   Peter   Larry         13
2   Steve    John         19
3   Peter  Parker          5
4   Larry   Peter          7

In [124]: df[~(np.triu(df.person1.values[:,None] == df.person2.values)).any(0)]
Out[124]: 
  person1 person2 someMetric
0    John   Steve         20
1   Peter   Larry         13
3   Peter  Parker          5
</code></pre>

python pandas duplicates