title: Creating pivot table using pandas
body: <p>I have pandas dataframe which has two columns - ID and an item associated with ID:</p>
  
  <pre><code>id item
  1  apple
  2  banana
  2  apple
  3  avocado
  </code></pre>
  
  <p>(there are duplicate ID's)</p>
  
  <p>And want to transform it into a table like this:</p>
  
  <pre><code>id  apple banana avocado
  ------------------------
  1     1     0      0
  2     1     1      0
  3     0     0      1
  </code></pre>
  
  <p>I thought pandas pivot or pivot table did just this, but I am not getting expected outcomes when trying those functions.
  So far I have tried</p>
  
  <pre><code>df.pivot(index="id", columns="items") # gives ValueError: Index contains duplicate entries, cannot reshape
  df.pivot_table(index="id", columns="items", aggfunc='count') # gives an empty dataframe
  </code></pre>
  
  <p>What can I do to accomplish the desired result?</p>