Select rows where a particular column has is two characters long
<p>I know how to select rows by value in a particular column. For example:</p>

<pre><code>df.loc[df['column_name'] == some_value]
</code></pre>

<p>How do I modify that so the column value is exactly two capital letters. E.g. AB or FZ.</p>

<p>you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.match.html" rel="nofollow">.str.match()</a> method:</p>

<pre><code>In [55]: df
Out[55]:
     col
0     xy
1    ABC
2     ZS
3  AAAAA
4     XC

In [56]: df.col.str.match(r'^[A-Z]{2}$')
Out[56]:
0    False
1    False
2     True
3    False
4     True
Name: col, dtype: bool

In [57]: df[df.col.str.match(r'^[A-Z]{2}$')]
Out[57]:
  col
2  ZS
4  XC
</code></pre>

python pandas dataframe