title: How to calculate counts on pandas pivot_table
body: <p>I have data something like this</p>
  
  <pre><code>import random
  import pandas as pd
  
  jobs = ['Agriculture', 'Crafts', 'Labor', 'Professional']
  
  df = pd.DataFrame({
      'JobCategory':[random.choice(jobs) for i in range(300)],
      'Region':[random.randint(1,5) for i in range(300)],
      'MaritalStatus':[random.choice(['Not Married', 'Married']) for i in range(300)]
  })
  </code></pre>
  
  <p>And I want a simple table showing the count of jobs in each region.</p>
  
  <pre><code>print(pd.pivot_table(df,
             index='JobCategory',
             columns='Region',
             margins=True,
             aggfunc=len))
  </code></pre>
  
  <p>Output is</p>
  
  <pre><code>             MaritalStatus                               
  Region                   1     2     3     4     5    All
  JobCategory                                              
  Agriculture           13.0  23.0  17.0  18.0   8.0   79.0
  Crafts                16.0  13.0  18.0  19.0  14.0   80.0
  Labor                 15.0  11.0  19.0  11.0  14.0   70.0
  Professional          22.0  17.0  16.0   7.0   9.0   71.0
  All                   66.0  64.0  70.0  55.0  45.0  300.0
  </code></pre>
  
  <p>I assume "MaritalStatus" is showing up in the output because that is the column that the count is being calculated on.  How do I get Pandas to calculate based on the Region-JobCategory count and ignore extraneous columns in the dataframe?</p>
  
  <p>Added in edit ---</p>
  
  <p>I am looking for a table with margin values to be output.  The values in the table I show are what I want but I don't want MaritalStatus to be what is counted.  If there is a Nan in that column, e.g. change the column definition to</p>
  
  <pre><code>'MaritalStatus':[random.choice(['Not Married', 'Married'])
                   for i in range(299)].append(np.NaN)
  </code></pre>
  
  <p>This is the output (both with and without <code>values = 'MaritalStatus',</code>)</p>
  
  <pre><code>             MaritalStatus                             
  Region                   1     2     3     4     5  All
  JobCategory                                            
  Agriculture           16.0  14.0  16.0  14.0  16.0  NaN
  Crafts                25.0  17.0  15.0  14.0  16.0  NaN
  Labor                 14.0  16.0   8.0  17.0  15.0  NaN
  Professional          13.0  14.0  14.0  13.0  13.0  NaN
  All                    NaN   NaN   NaN   NaN   NaN  0.0
  </code></pre>