title: DataFrame transpose from List
body: <p>As most pandas problems, I am guessing the problem has been dealt with before, but I can't find a direct answer and I'm also worried about performance. My dataset is large, so I'm hoping to find the <em>most efficient</em> way of doing this.</p>
  
  <p><strong>The Problem</strong>
  I have 2 dataframes - dfA contains a list of id's from dfB. I'd like to </p>
  
  <ol>
  <li>transpose those IDs as columns</li>
  <li>replace the IDs with a value looked up from dfB</li>
  <li>collapse repeated columns and aggregate with sum</li>
  </ol>
  
  <p>Here's an illustration:</p>
  
  <p><strong>dfA</strong></p>
  
  <pre><code>dfA = pd.DataFrame({'a_id':['0000001','0000002','0000003','0000004'],
                      'list_of_b_id':[['2','3','7'],[],['1','2','3','4'],['6','7']]
                     })
  
  +------+--------------+
  | a_id | list_of_b_id |
  +------+--------------+
  | 1    | [2, 3, 7]    |
  +------+--------------+
  | 2    | []           |
  +------+--------------+
  | 3    | [1, 2, 3, 4] |
  +------+--------------+
  | 4    | [6, 7]       |
  +------+--------------+
  </code></pre>
  
  <p><strong>dfB</strong></p>
  
  <pre><code>dfB = pd.DataFrame({'b_id':['1','2','3','4','5','6','7'],
                     'replacement': ['Red','Red','Blue','Red','Green','Blue','Red']
                    })
  
  +------+-------------+
  | b_id | replacement |
  +------+-------------+
  | 1    | Red         |
  +------+-------------+
  | 2    | Red         |
  +------+-------------+
  | 3    | Blue        |
  +------+-------------+
  | 4    | Red         |
  +------+-------------+
  | 5    | Orange      |
  +------+-------------+
  | 6    | Blue        |
  +------+-------------+
  | 7    | Red         |
  +------+-------------+
  </code></pre>
  
  <p><strong>Goal (Final Result)</strong>
  Here is what I'm hoping to eventually get to, in the most efficient way possible. </p>
  
  <p>In reality, I may have over 5M obs in both dfA and dfB, and ~50 unique values for replacement in dfB, which explains why I need to do this in dynamic fashion and not just hard-code it.</p>
  
  <pre><code>+------+-----+------+
  | a_id | Red | Blue |
  +------+-----+------+
  | 1    | 2   | 1    |
  +------+-----+------+
  | 2    | 0   | 0    |
  +------+-----+------+
  | 3    | 3   | 1    |
  +------+-----+------+
  | 4    | 1   | 1    |
  +------+-----+------+
  </code></pre>