title: Pandas: How to group (and sum) by category and retain information from subcategory
body: <p>This is a follow-up question to <a href="https://stackoverflow.com/questions/51077487/pandas-how-to-subset-and-sum-top-n-observations-within-subcategories">Pandas: How to subset (and sum) top N observations within subcategories?</a> There it was demonstrated how you could find the sum of the top 3 months for each year in this dataframe:</p>
  
  <p><strong>Example dataframe</strong></p>
  
  <pre><code>    year      month   passengers
  0    1949    January         112
  1    1949   February         118
  2    1949      March         132
  3    1949      April         129
  4    1949        May         121
  5    1949       June         135
  .
  .
  .
  137  1960       June         535
  138  1960       July         622
  139  1960     August         606
  140  1960  September         508
  141  1960    October         461
  142  1960   November         390
  143  1960   December         432
  </code></pre>
  
  <p>So that you'd end up with this:</p>
  
  <pre><code>    year  passengers
  0   1949         432
  1   1950         498
  2   1951         582
  3   1952         690
  4   1953         779
  5   1954         859
  6   1955        1026
  7   1956        1192
  8   1957        1354
  9   1958        1431
  10  1959        1579
  11  1960         176
  </code></pre>
  
  <p>The number <code>432 for 1949</code> is the sum of <code>148+148+136 for the months July, August and September.</code>
  My question now is this:</p>
  
  <p><strong>Is it possible to do the same calculations, and at the same time keep the corresponding subcategories as a list in it's own column?</strong> </p>
  
  <p><strong>Desired output</strong></p>
  
  <p>(I've only checked the actual sum for 1949. 1950 is made up):</p>
  
  <pre><code>        year  passengers  months
      0   1949         432  July, August, September 
      1   1950         498  August, September, December
      2   1951         582  .
      3   1952         690  .
      4   1953         779  .
      5   1954         859  .
      6   1955        1026  .
      7   1956        1192  .
      8   1957        1354  .
      9   1958        1431  .
      10  1959        1579  .
      11  1960         176  .
  </code></pre>
  
  <p><strong>Reproducible code and data:</strong></p>
  
  <pre><code>import pandas as pd
  import seaborn as sns
  df = sns.load_dataset('flights')
  print(df.head())
  
  df2 = df.groupby('year')['passengers'].apply(lambda x: x.nlargest(3).sum()).reset_index()
  print(df2.head())
  </code></pre>
  
  <p>df:</p>
  
  <pre><code>   year     month  passengers
  0  1949   January         112
  1  1949  February         118
  2  1949     March         132
  3  1949     April         129
  4  1949       May         121
  </code></pre>
  
  <p>df2:</p>
  
  <pre><code>   year  passengers
  0  1949         432
  1  1950         498
  2  1951         582
  3  1952         690
  4  1953         779
  </code></pre>
  
  <p>Thank you for any suggestions!</p>