title: KeyError when running df through function
body: <p>I'm trying to apply the function below to a dataframe and return only the rows that qualify, but get an KeyError. What am I doing wrong?</p>
  
  <pre><code>N = 100
  
  np.random.seed(0)
  
  df = pd.DataFrame(
      {'X':np.random.uniform(-3,10,N),
       'Y':np.random.uniform(-3,10,N),
       'Z':np.random.uniform(-3,10,N),
      })
  
  def func_sec(df):
      for i in range(len(df)):
          for k in range( i+1, len(df)+1 ):
              df_sum = df[i:k].sum()
              m = (df_sum&gt;2).all() &amp; (df_sum.sum()&gt;10)
              return df[m]
  
  func_sec(df)
  </code></pre>