title: Selecting columns with two levels (binary variables) from a pandas dataframe
body: <p>I'm trying to select data fields that have only two values [0, 1]. My code works for one column, however it fails when I try to loop through many columns.  </p>
  
  <p>Here is the sample dataset:</p>
  
  <pre><code>df = pd.DataFrame({'a':np.random.randint(0,2, size = (10)),
                      'b':np.random.randint(0,2, size = (10)),
                      'c':np.random.randint(0,6, size = (10)),
                     'd': ['x', 'y']*5
                    })
  df
  </code></pre>
  
  <p>data looks like this: </p>
  
  <pre><code>df.to_dict()
  {'a': {0: 1, 1: 1, 2: 0, 3: 0, 4: 0, 5: 0, 6: 0, 7: 1, 8: 0, 9: 1},
   'b': {0: 0, 1: 0, 2: 0, 3: 0, 4: 0, 5: 1, 6: 1, 7: 1, 8: 0, 9: 1},
   'c': {0: 1, 1: 1, 2: 2, 3: 2, 4: 5, 5: 2, 6: 2, 7: 0, 8: 4, 9: 3},
   'd': {0: 'x',
    1: 'y',
    2: 'x',
    3: 'y',
    4: 'x',
    5: 'y',
    6: 'x',
    7: 'y',
    8: 'x',
    9: 'y'}}
  </code></pre>
  
  <p>Columns 'a' and 'b' should be selected. 
  The line below yields true, which is what I want. </p>
  
  <pre><code>list(set(df[mylist[0]])) == [0,1]
  </code></pre>
  
  <p>Why am I getting a keyError when I run this:</p>
  
  <pre><code>mylist = list(df.columns)
  
  for i in mylist:
      if list(set(df[mylist.index(i)])) == [0,1]:
          print(i)
  </code></pre>
  
  <p>KeyError: 0</p>
  
  <p>I'm trying to output list of columns names, that satisfy the IF condition.</p>