title: Sum and collapse two rows in pandas if two values are equal (order does not matter)
body: <p>I am analyzing a dataset that has an Origin ID (Column A), a Destination ID (Column B), and how many trips have happened between them (Column Count). Now I want to sum the A-B trips with the B-A trips. This sum is the total number of trips between A and B.</p>
  
  <p>Here is how my data looks like (it is not necessarily ordered in the same way):</p>
  
  <pre><code>    In [1]: group_station = pd.DataFrame([[1, 2, 100], [2, 1, 200], [4, 6, 5] , [6, 4, 10], [1, 4, 70]], columns=['A', 'B', 'Count'])
      Out[2]: 
         A  B Count
      0  1  2 100
      1  2  1 200
      2  4  6 5
      3  6  4 10
      4  1  4 70
  </code></pre>
  
  <p>And I want the following output:</p>
  
  <pre><code>       A  B C
      0  1  2 300
      1  4  6 15
      4  1  4 70
  </code></pre>
  
  <p>I have tried groupby and setting the index to both variables with no success. Right now I am doing a very inefficient double loop, that is too slow for the size of my dataset. </p>
  
  <p>If it helps this is the code for the double loop (I removed some efficiency modifications to make it more clear):</p>
  
  <pre><code># group_station is the dataframe
  collapsed_group_station = np.zeros(len(group_station), 3))
  for i, row in enumerate(group_station.iterrows()):
      start_id = row[0][0]
      end_id = row[0][1]
      count = row[1][0]
  
      for check_row in group_station.iterrows():
          check_start_id = check_row[0][0]
          check_end_id = check_row[0][1]
          check_time = check_row[1][0]
  
          if start_id == check_end_id and end_id == check_start_id:
              new_group_station[i][0] = start_id
              new_group_station[i][1] = end_id
              new_group_station[i][2] = time + check_time
              break
  </code></pre>
  
  <p>I have ideas of how to make this code more efficient, but I wanted to know if there is a way of doing it without looping.</p>