title: Transforming column dataframe pandas into sequence
body: <p>I have data and convert into dataframe</p>
  
  <pre><code>d = [
    (1,70399,0.988375133622),
    (1,33919,0.981573492596),
    (1,62461,0.981426807114),
    (579,1,0.983018778374),
    (745,1,0.995580488899),
    (834,1,0.980942505189)
  ]
  
  df = pd.DataFrame(d, columns=['source', 'target', 'weight'])
  
  &gt;&gt;&gt; df
     source  target    weight
  0       1   70399  0.988375
  1       1   33919  0.981573
  2       1   62461  0.981427
  3     579       1  0.983019
  4     745       1  0.995580
  5     834       1  0.980943
  </code></pre>
  
  <p>I need transform column source into sequence, I have tried using </p>
  
  <pre><code>df.source = (df.source.diff() != 0).cumsum() - 1
  </code></pre>
  
  <p>but I just get :</p>
  
  <pre><code>&gt;&gt;&gt; df
     source  target    weight
  0       0   70399  0.988375
  1       0   33919  0.981573
  2       0   62461  0.981427
  3       1       1  0.983019
  4       2       1  0.995580
  5       3       1  0.980943
  </code></pre>
  
  <p>I need transform value column target based value source, ideal result is :</p>
  
  <pre><code>&gt;&gt;&gt; df
     source  target    weight
  0       0   70399  0.988375
  1       0   33919  0.981573
  2       0   62461  0.981427
  3       1       0  0.983019
  4       2       0  0.995580
  5       3       0  0.980943
  </code></pre>
  
  <p>value <code>target</code> change match value in source, in <code>source</code>, <code>value</code> 1 change into 0, so i need change <code>value</code> 1 in <code>target</code> into 0 too</p>
  
  <p>How can I do that ? Maybe anyone can help me :)</p>
  
  <p>Thanks :)</p>