title: Creating a Results Grid from a Pandas DataFrame
body: <p>I have the following table of results in a <em>Pandas DataFrame</em>. Each player has been assigned an ID number:</p>
  
  <pre><code>+----------------+----------------+-------------+-------------+
  | Home Player ID | Away Player ID | Home Points | Away Points |
  +----------------+----------------+-------------+-------------+
  |              1 |              2 |           3 |           0 |
  |              3 |              4 |           1 |           1 |
  |              2 |              3 |           3 |           0 |
  |              4 |              1 |           3 |           0 |
  |              2 |              4 |           1 |           1 |
  |              3 |              1 |           1 |           1 |
  |              2 |              1 |           0 |           3 |
  |              4 |              3 |           1 |           1 |
  |              3 |              2 |           0 |           3 |
  |              1 |              4 |           0 |           3 |
  |              4 |              2 |           1 |           1 |
  |              1 |              3 |           1 |           1 |
  +----------------+----------------+-------------+-------------+
  </code></pre>
  
  <p>The aim is to create a 4x4 <em>numpy</em> matrix (dimensions equal to the number of players) and fill the matrix with the points they earned from games between the respective players.</p>
  
  <p>The matrix should end up like this:</p>
  
  <pre><code>+--------+---+---+---+---+
  | Matrix | 1 | 2 | 3 | 4 |
  +--------+---+---+---+---+
  |      1 | 0 | 3 | 1 | 0 |
  |      2 | 0 | 0 | 3 | 1 |
  |      3 | 1 | 0 | 0 | 1 |
  |      4 | 3 | 1 | 1 | 0 |
  +--------+---+---+---+---+
  </code></pre>
  
  <p>The left hand column is the ID number of the home players, with the column headers the IDs of the away players.</p>
  
  <p>For example, when the Home Player ID = 1 and the Away Player ID = 2, Player 1 earned 3 points, so the entry for the Matrix(1,2) <em>(or 0,1 because of the zero indexing)</em> would equal 3.</p>
  
  <p>I can just about manage to do this with two for loops, but it seems quite inefficient. Is there a better way to achieve this?</p>
  
  <p>Would really appreciate any advice!</p>