title: KeyError: True for conditional indexing in pandas DataFrame
body: <p>I have a dataframe containing two columns: one filled with a string (irrelevant), and the other one is (a reference to) a dataframe.</p>
  <p>Now I want to only keep the rows, where the dataframes in the second column have entries aka <code>len(df.index) &gt; 0</code> (there should be rows left, I don't care about columns).
  I know that sorting out rows like this works perfectly fine for me if I use it in a list comprehension and can do it on every entry by its own, like in the following example:</p>
  <pre><code>[do_x for a, inner_df 
   in zip(outer_df.index, outer_df[&quot;inner&quot;])
   if len(inner_df.index) &gt; 0]
  </code></pre>
  <p>But if I try using it for conditional indexing to create a shorter version of the dataframe, it will produce the error <code>KeyError: True</code>.</p>
  <p>I thought, that putting len() around it could be a problem so I also tried different approaches to check for zero rows. <em>In the following I show 4 examples of how I tried it</em>:</p>
  <pre><code># a) with the length of the index
  outer_df = outer_df.loc[len(outer_df[&quot;inner&quot;].index) &gt; 0, :]
  
  # b) same, but with lambda just like in the panda docs user guide
  # I used it on the other versions too, with no change in result
  outer_df = outer_df.loc[lambda df: len(df[&quot;inner&quot;]) &gt; 0, :]
  
  # c) switching
  outer_df = outer_df.loc[outer_df[&quot;inner&quot;].index.size &gt; 0, :]
  
  # d) even &quot;shorter&quot; version
  outer_df = outer_df.loc[not outer_df[&quot;inner&quot;].empty, :]
  </code></pre>
  <p>So... where is my error and can I even do it with conditional indexing or do I need to find another way?</p>
  <hr />
  <p>Edit: Changed and added some sentences above for more clarity plus added all below.</p>
  <p>I know, that the filtering here kind of works through creating a Series the same length as the dataframe consisting of &quot;True&quot; and &quot;False&quot; after a comparison, resulting in keeping only the rows that contain a &quot;True&quot;.</p>
  <p>I do not however see a fundamental difference between my attempt to create such a list and the following examples (Source <a href="https://www.geeksforgeeks.org/selecting-rows-in-pandas-dataframe-based-on-conditions/" rel="nofollow noreferrer">https://www.geeksforgeeks.org/selecting-rows-in-pandas-dataframe-based-on-conditions/</a>):</p>
  <pre><code># 1. difference: the resulting Series is *not* altered
  # it just gets compared directly with here the value 80
  # -&gt; I thought this might be the problem, but then there is also #2
  df = df[df['Percentage'] &gt; 80]
  # or
  df = df.loc[df['Percentage'] &gt; 80]
  
  # 2. Here the entry is checked in a similar way to my c and d
  options = ['x', 'y']
  df = df[df['Stream'].isin(options)]
  # or 
  df = df.loc[df['Stream'].isin(options)]
  </code></pre>
  <p>In both, number two here and my versions c &amp; d, the entry in the cell (string // dataframe) is checked for something (is part of list // is empty).</p>