determine length (or number of digits) of every row in column
<p>I have a dataframe with columns that are <code>floats</code>. Some rows have <code>NaN</code> values.</p>

<p>I want to find rows where the length (or number of digits) of the number is <code>!=6</code>. </p>

<p>I tried the following:</p>

<pre><code>len(str(df['a'])) != 6
</code></pre>

<p>But this seems to only return only one Boolean value and not a Boolean for every row in the dataframe. </p>

<p>What is the correct way to do this? </p>

<p><strong>UPDATE</strong>:</p>

<p>Someone made a post with an answer similar to:</p>

<pre><code>df.query('a &lt;= 10**5')
</code></pre>

<p>That seemed to work nicely. Now, I want to add an additional condition where column b is not null. How do I do that in the query() function. </p>

<p>Cast it to a string and then use the string ops.</p>

<pre><code>df['a'].astype(str).str.len()
</code></pre>

<p>EDIT: To your more complete version, you might just go with:</p>

<pre><code>df[(df['a'].fillna(0) &lt; 100000) &amp; (pd.notnull(df[b]))]
</code></pre>

python pandas