title: Why is the Index of a Pandas DataFrame Slice different to its shape?
body: <p>I have a DataFrame, <code>df1</code>, which is a slice of <code>df</code>. <code>df</code> is multiindexed and has shape <code>(8,)</code>. The slice removes some of the second level of <code>df</code>. When I do <code>df1.shape</code> it returns <code>(4,)</code> - all good - but when I do <code>df1.index.levels[0]</code> this returns <code>(4,)</code>. How come this happens?</p>
  
  <pre><code>In [ ]:       
  arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux']),
              np.array(['one', 'two', 'one', 'two', 'one', 'two', 'one', 'two'])]
  
  
      df = pd.DataFrame(np.random.randn(8,2), index=arrays)
      df
  
  Out [ ]:
              0        1
  bar one   -0.447155  -0.323073
      two    0.115899  -0.015561
  baz one   -0.272498  1.847073
      two   -0.399948  -0.264327
  foo one    0.169687  -1.708543
      two    1.154434  0.878936
  qux one    0.535721  0.437186
      two   -1.203431  0.568412
  
  In [ ]:
      df1=df[df[1]&gt;0]
  
  Out [ ]:
              0           1
      baz one  -0.272498  1.847073
      foo two  1.154434   0.878936
      qux one  0.535721   0.437186
          two  -1.203431  0.568412
  </code></pre>
  
  <p>Now for the weird bit</p>
  
  <pre><code>In [ ]:
      df1=df[df[1]&gt;0]
      print(df1.index.levels[0], df1.index.levels[0].shape)
  
  Out [ ]:
      Index(['bar', 'baz', 'foo', 'qux'], dtype='object') (4,)
  </code></pre>
  
  <p>I find this strange as there is no <code>bar</code> shown in <code>df1</code>. What is the reason behind this?</p>
  
  <p><em>My guess is it is something to do with copying/not copying but I don't understand why.</em></p>