Pandas - filter and regex search the index of DataFrame
<p>I have a DataFrame in which the columns are MultiIndex and the index is a list of names, ie <code>index=['Andrew', 'Bob', 'Calvin',...]</code>.</p>

<p>I would like to create a function to return all rows of the dataframe that use the name 'Bob' or perhaps start with the letter 'A' or start with lowercase. How can this be done?</p>

<p>I looked into the <code>df.filter()</code> with the regex argument, but it fails and I get:</p>

<pre><code>df.filter(regex='a')
TypeError: expected string or buffer
</code></pre>

<p>or:</p>

<pre><code>df.filter(regex=('a',1)
TypeError: first argument must be string or compiled pattern
</code></pre>

<p>I've tried other things such as passing <code>re.compile('a')</code> to no avail.</p>