title: Pandas .filter() method with lambda function
body: <p>I'm trying to understand the <a href="https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.filter.html" rel="nofollow noreferrer">.filter()</a> method in Pandas. I'm not sure why the below code doesn't work:</p>
  
  <pre><code># Load data
  from sklearn.datasets import load_iris
  import pandas as pd
  data = load_iris()
  df = pd.DataFrame(data.data, columns=data.feature_names)
  
  # Set arbitrary index (is this needed?) and try filtering:
  indexed_df = df.copy().set_index('sepal width (cm)')
  test = indexed_df.filter(lambda x: x['petal length (cm)'] &gt; 1.4)
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>TypeError: 'function' object is not iterable
  </code></pre>
  
  <p>I appreciate there are simpler ways to do this (e.g. Boolean indexing) but I'm trying to understand for learning purposes why <code>filter</code> fails here when it works for a <code>groupby</code> as shown below: </p>
  
  <p>This works:    </p>
  
  <pre><code> filtered_df = df.groupby('petal width (cm)').filter(lambda x: x['sepal width (cm)'].sum() &gt; 50)
  </code></pre>