using len() in Pandas dataframe
<p>This is the look of my <code>dataframe</code>:</p>

<p><img src="http://i.stack.imgur.com/9C22C.png" alt="dataframe">
and I want to list a list of senators whose surname is more than 9 characters long</p>

<p>So I think the code should be like this:</p>

<pre><code>df[len(df.Surname) &gt;9 ]
</code></pre>

<p>but there will be a compile error, where did I go wrong?</p>

<p>Have a look at the python <a href="https://docs.python.org/3.4/library/functions.html#filter" rel="nofollow">filter</a> function. It does exactly what you want.</p>

<pre><code>df = [
    {"Surname": "Bullock-ish"},
    {"Surname": "Cash"},
    {"Surname": "Reynolds"},
]
longnames = list(filter(lambda s: len(s["Surname"]) &gt; 9, df))
print(longnames)

&gt;&gt;[{'Surname': 'Bullock-ish'}]
</code></pre>

<p>Sytse</p>

python pandas dataframe