title: How to compare value of second column with same values of first column in pandas dataframe?
body: <p>How to extract and compare values of second column in a data frame for all the same values of first column in same data frame?</p>
  
  <p>I have a data frame as 'df':</p>
  
  <pre><code>Name         Datetime
  Bob          26-04-2018 12:00:00
  Claire       26-04-2018 12:00:00
  Bob          26-04-2018 12:30:00
  Grace        27-04-2018 08:30:00
  Bob          27-04-2018 09:30:00
  </code></pre>
  
  <p>I want to add a new column to the data frame as df['Id'] such that, for users having same names, if the datetime values have a difference of not more than 30 min, they would be assigned the same value of Id, and if the datetime difference is greater than 30 min, then it would be assigned a different id.</p>
  
  <p>I think it could be achieved using iterating over loops but I am not sure how to do it. Also, is there a better way to do this as I have a huge data set?</p>
  
  <p>My expected output of the data frame would be as:</p>
  
  <pre><code>Name         Datetime                 Id
  Bob          26-04-2018 12:00:00      1
  Claire       26-04-2018 12:00:00      2
  Bob          26-04-2018 12:10:00      1
  Bob          26-04-2018 12:20:00      1
  Claire       27-04-2018 08:30:00      3
  Bob          27-04-2018 09:30:00      4
  </code></pre>
  
  <p>Any help would be appreciated.
  Thanks</p>