title: String replace with condition
body: <p>I have two pandas dataframes. One contains text, the other a set of terms i'd like to search for and replace within the text. I have a method to do this, however I would like to add conditions. The conditions are, if the term contains the word either 'no' or 'none' up to three words before, to not replace.</p>
  
  <p>In the example below ID 2 is incorrectly replaced based on the conditions above.</p>
  
  <p>Example text:</p>
  
  <pre><code>d = {'ID': [1, 2, 3], 'Text': ['here is some random text', 'no such random text, none here', 'more random text']}
  text_df = pd.DataFrame(data=d)
  </code></pre>
  
  <p>Example terms:</p>
  
  <pre><code>d = {'Replace_item': ['&lt;RANDOM_REPLACED&gt;', '&lt;HERE_REPLACED&gt;', '&lt;SOME_REPLACED&gt;'], 'Text': ['random', 'here', 'some']}
  replace_terms_df = pd.DataFrame(data=d)
  </code></pre>
  
  <p>Method for replacing terms (with ID 2 being incorrect based on conditions):</p>
  
  <pre><code>text_df['Text'] = [z.replace(x, y) for (x, y, z) in zip(replace_terms_df.Text, replace_terms_df.Replace_item, text_df.Text)]
  </code></pre>
  
  <p>Target dataframe (considering the conditions):</p>
  
  <pre><code>d = {'ID': [1, 2, 3], 'Text': ['&lt;HERE_REPLACED&gt; is &lt;SOME_REPLACED&gt; &lt;RANDOM_REPLACED&gt; text', 'no such random text, none here', 'more  &lt;RANDOM_REPLACED&gt; text']}
  target_df = pd.DataFrame(data=d)
  </code></pre>
  
  <p>Please ask if you need clarity. Thank you.</p>