title: how to convert column in this way in pandas
body: <p>original data is:
  </p>
  
  <pre><code>df=pd.DataFrame({'A': [1]*3 + [2]*3 + [1]*4 + [3]*5,
                   'B': [1.5]*2 + [2]*4 + [1.5]*5 + [3.2]*4})
  </code></pre>
  
  <p>how can I convert column <code>A</code> and <code>B</code> to:
  <a href="https://i.stack.imgur.com/Qesbb.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Qesbb.jpg" alt="enter image description here"></a></p>
  
  <p>and rule of <code>A_con</code> and <code>B_con</code> is: </p>
  
  <p>A_con[0]=0; if(A[i]>A[i-1], A_con[i]=True, if(A[i]==A[i-1] &amp;&amp; A_con[i-1]==True, A_con[i]=True, A_con[i]=False))</p>
  
  <p>rule of days_A and days_B is:</p>
  
  <p>if(A_con[i]==True, days_A[i]=days_A[i-1]+1, days_A[i]=0)</p>