title: comparing rows in dataframe
body: <p>i have trouble with one of my task. in my <strong>first case</strong>,  i need to comparing some variables in my dataframe, then if they are the same, it will return a same value of identifier column.</p>
  
  <p>here's my multiple sorted dataframe looks like</p>
  
  <pre><code>| no | age| gender | income_group | cars
  | 1  | 15 |  male  |       0      | ford
  | 2  | 15 |  male  |       0      | renault
  | 3  | 15 |  female|       1      | bmw
  | 4  | 16 |  female|       1      | bmw
  | 5  | 16 |  female|       1      | mercedes
  | 6  | 16 |  female|       1      | honda
  </code></pre>
  
  <p>i want some code that will compare each rows at this sorted dataframe and if [age, gender, income_group] identically the same for some rows, it will copying the first [no] columns value to replace the others</p>
  
  <p>the code will make my dataframe looks like this</p>
  
  <pre><code>| no | age| gender | income_group | cars
  | 1  | 15 |  male  |       0      | ford
  | 1  | 15 |  male  |       0      | renault
  | 3  | 15 |  female|       1      | bmw
  | 4  | 16 |  female|       1      | bmw
  | 4  | 16 |  female|       1      | mercedes
  | 4  | 16 |  female|       1      | honda
  </code></pre>
  
  <p>is there any possible way to do like this in python?</p>
  
  <p><strong>Edited:</strong>
  <strong>my second case</strong> get more complicated where i find some identical [age, gender, income_group] variables but has the same [cars] value, i want it to be consider as different individual in this case different [no] values</p>
  
  <p>if expand the dataframe and get a colomn looks like this</p>
  
  <pre><code>| no | age| gender | income_group | cars
  | 1  | 15 |  male  |       0      | ford
  | 2  | 15 |  male  |       0      | renault
  | 3  | 15 |  female|       1      | bmw
  | 4  | 16 |  female|       1      | bmw
  | 5  | 16 |  female|       1      | mercedes
  | 6  | 16 |  female|       1      | honda
  
  | 7  | 17 |  male  |       0      | bmw
  | 8  | 17 |  male  |       0      | honda
  | 9  | 17 |  male  |       0      | bmw
  | 10 | 17 |  male  |       0      | honda
  | 11 | 17 |  male  |       0      | renault
  </code></pre>
  
  <p>one person can't has the same cars value, the code will make the df:</p>
  
  <pre><code>| 7  | 17 |  male  |       0      | bmw
  | 7  | 17 |  male  |       0      | honda
  | 9  | 17 |  male  |       0      | bmw
  | 9  | 17 |  male  |       0      | honda
  | 9  | 17 |  male  |       0      | renault
  </code></pre>
  
  <p>whit jezrael solution:</p>
  
  <pre><code>df['a'] = df.duplicated(['age','gender','income_group', 'cars'], keep=False).cumsum()
  
  df['no'] = df.groupby(['age','gender','income_group','a'], sort=False)['no'].transform('first')
  df = df.drop('a', axis=1)
  </code></pre>
  
  <p>i get:</p>
  
  <pre><code>no  age  gender  income_group      cars  a
   0   15    male             0      ford  0
   0   15    male             0   renault  0
   2   15  female             1       bmw  0
   3   16  female             1       bmw  0
   3   16  female             1  mercedes  0
   3   16  female             1     honda  0
   6   17    male             0       bmw  1
   7   17    male             0     honda  2
   8   17    male             0       bmw  3
   9   17    male             0     honda  4
   9   17    male             0   reanult  4
  </code></pre>