title: Python Pandas DataFrame pivot_table bizarre values
body: <p>"Bizarre" is such an emotionally charged word.</p>
  
  <p>Assume that I have 5 students: A, B, C, D, and E.  Each of these students grades two of their peers on a writing assignment.  The data is as follows:</p>
  
  <pre><code>peer_review = pd.DataFrame({
      'Student': ['A', 'A', 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'C', 'D', 'D', 'D', 'D', 'E', 'E'],
      'Assessor': ['B', 'C', 'A', 'D', 'D', 'D', 'B', 'D', 'D', 'D', 'A', 'A', 'A', 'E', 'C', 'E'],
      'Score': [72, 53, 92, 100, 2, 90, 75, 50, 50, 47, 97, 86, 41, 17, 47, 29]})
  </code></pre>
  
  <p>Now, in some cases an assessor graded the student's assignment more than once.  Maybe the student turned it in and revised several times.  Maybe the assessor was drunk and didn't remember that he had already graded this student's assignment.  In any case, I would like to be able to see a list of all scores that each assessor gave to each student.  I tried to do this as follows:</p>
  
  <pre><code>peer_review.pivot_table(
      index='Student',
      columns='Assessor',
      values='Score',
      aggfunc=identity)
  </code></pre>
  
  <p>I can already hear you asking --- What is the "identity" function?  It's this:</p>
  
  <pre><code>def identity(x):
      return x
  </code></pre>
  
  <p>However, when I run this the pivot_table function repeatedly, it gives me different answers each time for the cells that have multiple values.</p>
  
  <p>So, here are the questions:</p>
  
  <ol>
  <li>What is the significance of the numbers that seem to change randomly as I run the pivot_table function repeatedly?</li>
  <li>How do I fix the identity function so that it returns a simple list of all the scores when an assessor graded the same assignment more than once?</li>
  </ol>
  
  <p><strong>------------------UPDATE #1:------------------</strong></p>
  
  <p>I found that it is a pandas Series object that is being passed to the identity function.  I changed the identity function to this:</p>
  
  <pre><code>def identity(x):
      return x.values
  </code></pre>
  
  <p>This still gives me the bizarre random numbers.  Realizing that x.values is a numpy.ndarray, I then tried this:</p>
  
  <pre><code>def identity(x):
      return x.values.tolist()
  </code></pre>
  
  <p>This results in a ValueError exception.  ("Function does not reduce.")</p>
  
  <p><strong>------------------UPDATE #2:------------------</strong></p>
  
  <p>The workaround proposed by ZJS works perfectly.  Still wondering why pivot_table has failed me.</p>