title: How can I create a Pivot Table that show sum() of group values, using my Pandas Data Frame?
body: <p>My <code>df1</code>:</p>
  <pre><code>               cnpj     num_doc    bc_icms
  0    02817342000124  0000010154   17827.07
  1    54921580000189  0000112428  108000.00
  2    08953538000122  0000012865     232.00
  3    08953538000122  0000012865     239.00
  4    08953538000122  0000012865     215.00
  5    07374346000107  0000014224     320.12
  6    07374346000107  0000014231     385.04
  7    07374346000107  0000014263     401.28
  8    07374346000107  0000014279     391.26
  9    02364118000124  0000015263   37353.10
  10   02364118000124  0000015264   56214.14
  </code></pre>
  <p>The output of <code>df1.dtypes</code>:</p>
  <pre><code>cnpj        object
  num_doc     object
  bc_icms    float64
  dtype: object
  </code></pre>
  <p>So.... I'm trying to create a pivot table to answer the following question:</p>
  <blockquote>
  <p>What is the <code>sum</code> of <code>bc_icms</code> for each <code>cnpj</code>?</p>
  </blockquote>
  <p>This is what I've wrote:</p>
  <pre><code>indexes = [np.array(df1['cnpj']), np.array(df1['num_doc'])]
  pt1 = pd.DataFrame(df1['bc_icms'], index=indexes)
  print pt1
  </code></pre>
  <p>And here's the output:</p>
  <pre><code>                           bc_icms
  02817342000124 0000010154      NaN
  54921580000189 0000112428      NaN
  08953538000122 0000012865      NaN
                 0000012865      NaN
                 0000012865      NaN
  07374346000107 0000014224      NaN
                 0000014231      NaN
                 0000014263      NaN
                 0000014279      NaN
  02364118000124 0000015263      NaN
                 0000015264      NaN
                 0000015265      NaN
  07720786000160 0000020128      NaN
  </code></pre>
  <p>I think this is the pivot table structure that I want! Good! But...</p>
  <blockquote>
  <p>How can I fix these NaN's ?</p>
  <p>How can I create a &quot;sum&quot; line for each cnpj ?</p>
  </blockquote>
  <p>Example in Excel:</p>
  <p><a href="https://i.stack.imgur.com/lW1YT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/lW1YT.png" alt="example" /></a></p>