title: How do I use pandas to add a calculated column in a pivot table?
body: <p>I'm using pandas 0.16.0 &amp; numpy 1.9.2
  I did the following to add a calculated field (column) in the pivot table</p>
  
  <p>Set up dataframe as follows,</p>
  
  <pre><code>df = pd.DataFrame({'A' : ['one', 'one', 'two', 'three'] * 6, 'B' : ['A', 'B', 'C'] * 8, 'C' : ['foo', 'foo', 'foo', 'bar', 'bar', 'bar'] * 4, 'D' : np.random.randn(24), 'E' : np.random.randn(24), 'F' : [datetime.datetime(2013, i, 1) for i in range(1, 13)] + [datetime.datetime(2013, i, 15) for i in range(1, 13)]})
  </code></pre>
  
  <p>Pivoted the data frame as follows,</p>
  
  <pre><code>df1 = df.pivot_table(values=['D'],index=['A'],columns=['C'],aggfunc=np.sum,margins=False)
  </code></pre>
  
  <p>Tried adding a calculated field as follows, but I get an error (see below),</p>
  
  <pre><code>df1['D2'] = df1['D'] * 2
  </code></pre>
  
  <p>Error,</p>
  
  <pre><code>ValueError: Wrong number of items passed 2, placement implies 1
  </code></pre>