title: Filtering a pandas series using a lambda expression that operates on individual elements
body: <p>I'm trying to using pandas for chaining together map and filter operations.
  I've come across several options, partly outlined in here: 
  <a href="https://stackoverflow.com/questions/28272137/pandas-how-to-filter-a-series">Pandas How to filter a Series</a></p>
  
  <p>To summarize,</p>
  
  <pre><code>s = Series(range(10))
  
  s.where(s &gt; 4).dropna()
  s.where(lambda x: x &gt; 4).dropna()
  
  s.loc[s &gt; 4]
  s.loc[lambda x: x &gt; 4]
  
  s.to_frame(name='x').query("x &gt; 4")
  </code></pre>
  
  <p>This is fine for numerical comparisons and equality checks, but it doesn't work for predicates involving other operations. 
  For a simple example, consider matching against the first character of a string.</p>
  
  <pre><code>s = Series(['aa', 'ab', 'ba'])
  s.loc[lambda x: x.startswith('a')] # fails
  </code></pre>
  
  <p>This fails with a message like "Series has no attribute 'startswith'" since the argument <code>x</code> passed to the lambda expression in the second line is the series itself, rather than the individual elements it contains.</p>
  
  <p>Interestingly <code>map</code> does allow element-wise access:</p>
  
  <pre><code>Series(list('abcd')).map(lambda x: x.upper())
  # results in ['A', 'B', 'C', 'D'] even though Series has no upper method
  </code></pre>
  
  <p>While there's probably some clever ways to handle the <code>startswith</code> example, I'm hoping to find a more general solution where a series can be filtered using a function that accepts individual values from the collection. And ideally it would allow chaining together operations as in,</p>
  
  <pre><code>s = (Series(...)
          .map(...)
          .where(...)
          .map(...))
  </code></pre>
  
  <p>Is that supported in pandas?</p>
  
  <p>UPDATE:
  Scott provided the answer for cases where the value is a string, which can be handled with <code>Series.str</code> as described in his answer.</p>
  
  <p>But what about cases with a Series containing objects? 
  Is there any way to access their attributes or apply functions to them?</p>
  
  <p>I guess a standard way of managing that case would be to de-structure the the relevant fields of the object into a data frame, where each attribute is a column. Though there might be cases where someone would want to transform a collection of objects with map and filter(loc/where), without having to disassemble the complex type into a dataframe then immediately convert back.</p>
  
  <p>I'm partly trying to find an alternative to the standard map()/filter() functions in python, where the operations have to be nested in reverse.</p>
  
  <p>Ie,</p>
  
  <pre><code>map(function3, filter(function2, map(function1, collection)))
  </code></pre>