title: How to refer to the previous calculated field in Pandas
body: <p>I have a data set:</p>
  <pre><code>[0, 0.095, 0.104, 0.17, 0.189, 0.113, 0.198, 0.208, 0.274, 0.293, 0.312, 0.217, 0.208, 0.198, 0.17, 0.114, 0.095, 0.038]
  </code></pre>
  <p>I did some calculations in Excel like this:</p>
  <p><a href="https://i.stack.imgur.com/nKB1W.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nKB1W.png" alt="enter image description here" /></a></p>
  <p>I did the code in Python, but it does not work:</p>
  <pre><code>import pandas as pd
  
  import numpy as np
  
  df = pd.DataFrame({'A': [0, 0.095, 0.104, 0.17, 0.189, 0.113, 0.198, 0.208, 0.274, 0.293, 0.312, 0.217, 0.208, 0.198, 0.17, 0.114, 0.095, 0.038]})
  
  df['B'] = np.where((df['A'] - df['B'].shift(1)).abs() &gt; 0.1, df['A'], df['B'].shift(1))
  
  Result: KeyError: 'B'
  </code></pre>
  <p>How could I calculate the column 'B' in Python using Pandas without cycle?</p>