title: Ranking over multiple columns in pandas
body: <p>I have this data frame:</p>
  
  <pre><code>dict_data = {'id' : [1,1,1,2,2,2,2,2],
  'datetime' : np.array(['2016-01-03T16:05:52.000000000', '2016-01-03T16:05:52.000000000',
         '2016-01-03T16:05:52.000000000', '2016-01-27T15:45:20.000000000',
         '2016-01-27T15:45:20.000000000', '2016-11-27T15:08:04.000000000',
         '2016-11-27T15:08:04.000000000', '2016-11-27T15:08:04.000000000'], dtype='datetime64[ns]')}
  
  df_data=pd.DataFrame(dict_data)
  </code></pre>
  
  <p>The data looks like this </p>
  
  <p><a href="https://i.stack.imgur.com/UN3LC.png" rel="nofollow noreferrer">Data</a>  </p>
  
  <p>I want to rank over customer id and date, I used this code</p>
  
  <pre><code>    (df_data.assign(rn=df_data.sort_values(['datetime'], ascending=True)
  ....:                     .groupby(['datetime','id'])
  ....:                     .cumcount() + 1)
  ....:      .sort_values(['datetime','rn'])
  ....: )
  </code></pre>
  
  <p>I get a different rank by ID for each date:</p>
  
  <p><a href="https://i.stack.imgur.com/TD8A5.png" rel="nofollow noreferrer">table with rank</a></p>
  
  <p>What I would like to see is rank by ID but for the same datetime get the same rank for each ID.</p>