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>an approach in pandas</p>

<pre><code>df = pd.DataFrame(
{'person2':  {0: 'Steve', 1: 'Larry', 2: 'John', 3: 'Parker', 4: 'Peter'}, 
'person1': {0: 'John', 1: 'Peter', 2: 'Steve', 3: 'Peter', 4: 'Larry'}, 
'someMetric': {0: 20, 1: 13, 2: 19, 3: 5, 4: 7}})


print(df)
  person1 person2 someMetric
0    John   Steve         20
1   Peter   Larry         13
2   Steve    John         19
3   Peter  Parker          5
4   Larry   Peter          7


df['ordered-name'] = df.apply(lambda x: '-'.join(sorted([x['person1'],x['person2']])),axis=1)
df = df.drop_duplicates(['ordered-name'])
df.drop(['ordered-name'], axis=1, inplace=True)
print df
</code></pre>

<p>which gives:</p>

<pre><code>  person1 person2  someMetric
0    John   Steve          20
1   Peter   Larry          13
3   Peter  Parker           5
</code></pre>

python pandas duplicates