title: Rank by group after sorting in pandas
body: <p>I have a dataframe which looks like this</p>
  <pre><code>pd.DataFrame({'A': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'],
     ...:                    'B': ['C1', 'C1', 'C1', 'C1', 'C2', 'C2', 'C2', 'C2'],
     ...:                    'X': [1, 2, 1, 2, 2, 3, 4, 5],
     ...:                    'Y': [2, 1, 2, 2, 7, 5, 7, 7],
     ...:                    'Z': [2, 1, 2, 1, 5, 8, 1, 9]})
  Out[10]: 
     A   B  X  Y  Z
  0  A  C1  1  2  2
  1  B  C1  2  1  1
  2  C  C1  1  2  2
  3  D  C1  2  2  1
  4  E  C2  2  7  5
  5  F  C2  3  5  8
  6  G  C2  4  7  1
  7  H  C2  5  7  9
  </code></pre>
  <p>I need to sort the dataframe by columns B, X, Y, Z and then rank within each group of B.</p>
  <p>Resulting dataframe should look like this.</p>
  <pre><code>Out[12]: 
     A   B  X  Y  Z   R
  1  B  C1  2  1  1   1
  3  D  C1  2  2  1   2
  0  A  C1  1  2  2   3
  2  C  C1  1  2  2   4
  6  G  C2  4  7  1   1
  5  F  C2  3  5  2   2
  4  E  C2  2  1  5   3
  7  H  C2  5  7  9   4
  </code></pre>
  <p>I know I can use df.sort_values(['B', 'Z', 'Y', 'X']) to bring in right order but struggling to apply the rank.</p>
  <p>what is the 1 line of code for sorting and ranking?</p>