title: Grouping by a variable, sorting, and printing values from another column
body: <p>I have a data frame like this:</p>
  
  <pre><code>df = pd.DataFrame({'Subject': [101,101,101,101,101,101,101,101,101,102,102,102,102,102,102,102,102,102],
                     'Accuracy': [2, 0, 0, 0,4,4,6,4,3,3,3,6,6,6,4,3,2,7],
                     'Distance': [1,1,1,2,2,2,3,3,3,1,1,1,2,2,2,3,3,3],
                     'Onset': [1,7,8,9,1,5,5,3,2,6,7,8,9,5,4,3,2,4]})
  </code></pre>
  
  <p>For each subject, I want to print a csv that contains the Onsets for each distance. And the onsets would be sorted in ascending order. For example, file_Subject101_Distance1.csv would look like:</p>
  
  <pre><code>1 7 8
  </code></pre>
  
  <p>file_Subject101_Distance2.csv would be:</p>
  
  <pre><code>1 5 9
  </code></pre>
  
  <p>(because they'd be sorted) and so on. I can sort in pandas and have used 'groupby' but don't understand how to use them together to do what I want (or if that is even the best way).</p>