title: Pandas, get first, second and third preferred authors for every user
body: <p>I have a pandas dataframe of the form</p>
  
  <pre><code> userID      author_cat  vote 
   234         1246        5.0
   121         2954        3.2
   234         1246        2.1
   121         2954        1.4
   234         1578        3.3
   234         1246        4.5
   121         2954        1.1
   121         9341        3.2
  </code></pre>
  
  <p>Expected </p>
  
  <pre><code> userID      author_cat  vote  first_author     second_author   third_author
   234         1246        5.0   1246             1578            0
   121         2954        3.2   2954             9341            0
   234         1246        2.1   1246             1578            0
   121         2954        1.4   2954             9341            0
   234         1578        3.3   1246             1578            0
   234         1246        4.5   1246             1578            0
   121         2954        1.1   2954             9341            0
   121         9341        3.2   2954             9341            0
  </code></pre>
  
  <p>I want, for every user, to construct three columns, based on their ratings. The author that appears most (more books written by the same author, reviewed by one user) should appear in the "first_preferred_author" column (the categorical, like 1246). The same for the second and third preferred authors. If an author does not exist (either first, second and third, or even all three, the three new columns should contain 0). </p>
  
  <p>So far I managed to get the order of appearance of the authors based on the number of reviews by the users, with: </p>
  
  <pre><code>df_new.groupby('userID')['author_cat'].value_counts()
  </code></pre>
  
  <p>but I don't know what to do from here.</p>
  
  <p>EDIT: </p>
  
  <p>The above command returns a <code>pd.series.series</code> (?) which looks like this (on a real dataset):</p>
  
  <pre><code>userID  author_cat
  243     42994.0       6
          48986.0       5
          72473.0       3
          2505.0        2
          4371.0        2
          5270.0        2
          18764.0       2
          41267.0       2
          75183.0       2
          82066.0       2
          486.0         1
          571.0         1
          3507.0        1
          6343.0        1
          6524.0        1
          7530.0        1
          10539.0       1
          10679.0       1
          21123.0       1
          30948.0       1
          41305.0       1
          41479.0       1
          43715.0       1
          49236.0       1
          52183.0       1
          53204.0       1
          56812.0       1
          56916.0       1
          57911.0       1
          62266.0       1
                       ..
  278633  54862.0       1
          57422.0       1
          66639.0       1
          72642.0       1
          72712.0       1
          73809.0       1
          82105.0       1
          87066.0       1
          91189.0       1
          93458.0       1
          94608.0       1
          96674.0       1
          99025.0       1
  278843  80852.0       3
          3377.0        2
          4371.0        2
          2437.0        1
          2528.0        1
          5216.0        1
          18370.0       1
          30948.0       1
          35706.0       1
          37463.0       1
          40577.0       1
          62175.0       1
          62645.0       1
          81508.0       1
          92206.0       1
          92242.0       1
          93801.0       1
  Name: author_cat, Length: 96302, dtype: int64
  </code></pre>