title: Pandas - Python: Apply() and if/then logic
body: <p>I have the following DataFrames:</p>
  
  <pre><code>example  = pd.DataFrame({"dirr":[1,0,-1,-1,1,-1,0], 
                           "value": [125,130,80,8,150,251,18], 
                           "result":[np.NaN for _ in range(7)]})
  </code></pre>
  
  <p>I would like to perform the following operation with cummin() and cummax() on it:</p>
  
  <pre><code>example["result"].apply(lambda x : x= example["value"].cummax() if example["dirr"]==1
                             else x= example["value"].cummin() if example["dirr"]==-1
                             else x= NaN if if example["dirr"]==0
                                )
  </code></pre>
  
  <p>this is returning : <code>error: invalid syntax</code>.</p>
  
  <p>Could anyone help me straightening that one up?</p>
  
  <p>That would be the intended output: </p>
  
  <pre><code>example  = pd.DataFrame({"dirr":[1,0,-1,-1,1,-1,0], 
                           "value": [125,130,80,8,150,251,18], 
                           "result":[125, NaN, 80, 8, 150, 8, NaN]})
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>So as per the answer of @su79eu7k the following function would do:</p>
  
  <pre><code>def calc(x):
      if x['dirr'] == 1:
          return np.diag(example["value"].cummax())
      elif x['dirr'] == -1:
          return np.diag(example["value"].cummin())
      else:
          return np.nan
  </code></pre>
  
  <p>I should be able to shove that into a lambda but still am blocked on the syntax error... which I still don't see?</p>
  
  <pre><code>example["result"]=example.apply(lambda x : np.diag(x["value"].cummax()) if x["dirr"]==1
                                 else np.diag(x["value"].cummin()) if x["dirr"]==-1
                                 else NaN if x["dirr"]==0
                                )
  </code></pre>
  
  <p>A final little nudge form you guys would be hugely appreciated.</p>