title: How to aggregate unique count with pandas pivot_table
body: <p>This code:</p>
  <pre><code>df2 = (
      pd.DataFrame({
          'X' : ['X1', 'X1', 'X1', 'X1'], 
          'Y' : ['Y2', 'Y1', 'Y1', 'Y1'], 
          'Z' : ['Z3', 'Z1', 'Z1', 'Z2']
      })
  )
  g = df2.groupby('X')
  pd.pivot_table(g, values='X', rows='Y', cols='Z', margins=False, aggfunc='count')
  </code></pre>
  <p>returns the following error:</p>
  <pre><code>Traceback (most recent call last): ... 
  AttributeError: 'Index' object has no attribute 'index'
  </code></pre>
  <p>How do I get a Pivot Table with <strong>counts of unique values</strong> of one DataFrame column for two other columns?<br />
  Is there <code>aggfunc</code> for count unique? Should I be using <code>np.bincount()</code>?</p>
  <p>NB. I am aware of <code>pandas.Series.values_counts()</code> however I need a pivot table.</p>
  <hr />
  <p>EDIT: The output should be:</p>
  <pre><code>Z   Z1  Z2  Z3
  Y             
  Y1   1   1 NaN
  Y2 NaN NaN   1
  </code></pre>