title: Apply condition on DataFrame nested array
body: <p>From a Pandas DataFrame like the following:</p>
  
  <p><img src="https://i.stack.imgur.com/MkTfs.png" alt=""></p>
  
  <p>I want to apply a filter so it shows only the rows containing arrays with <strong>all elements</strong> within the range <code>10 &gt; Muon_pt &gt; 20</code> or <strong><em>some elements</em></strong> within the range <code>50 &gt; Electron_pt &gt; 100</code>.</p>
  
  <p>I do so by defining two functions:</p>
  
  <pre class="lang-py prettyprint-override"><code>def anyCut(x, minn , maxx):
      for i in x:
          if i &gt; minn and i &lt; maxx:
              return True
      return False
  
  def allCut(x, minn, maxx):
  
      for i in x:
          if i &lt; minn or i &gt; maxx:
              return False    
      return True
  </code></pre>
  
  <p>And then, applying it:</p>
  
  <pre class="lang-py prettyprint-override"><code>minElectronPt = 50.0
  maxElectronPt = 100.0
  
  minMuonPt = 10
  maxMuonPt = 20
  
  df[
      (
          (df["nElectron"]&gt;1)
          &amp;
          (df["nMuon"]&gt;1)
      )
      &amp;
      (
          (df["Electron_charge"].apply(lambda x: all(x == -1)))
          &amp;
          (
              (
                  df["Electron_pt"].apply(lambda x: anyCut(x, minElectronPt, maxElectronPt))
              )
  
              |
  
              (
                  df["Muon_pt"].apply(lambda x: allCut(x, minMuonPt, maxMuonPt))
              )
          )
      )
  ].head()
  </code></pre>
  
  <p>Getting:</p>
  
  <p><img src="https://i.stack.imgur.com/WcOf0.png" alt=""></p>
  
  <p>Is there any way to apply this filter without looping through the nested arrays (i.e to replace <code>anyCut</code> and <code>allCut</code> functions)?</p>