title: What rules does Pandas use to generate a view vs a copy?
body: <p>I'm confused about the rules Pandas uses when deciding that a selection from a dataframe is a copy of the original dataframe, or a view on the original.</p>
  
  <p>If I have, for example,</p>
  
  <pre><code>df = pd.DataFrame(np.random.randn(8,8), columns=list('ABCDEFGH'), index=range(1,9))
  </code></pre>
  
  <p>I understand that a <code>query</code> returns a copy so that something like</p>
  
  <pre><code>foo = df.query('2 &lt; index &lt;= 5')
  foo.loc[:,'E'] = 40
  </code></pre>
  
  <p>will have no effect on the original dataframe, <code>df</code>. I also understand that scalar or named slices return a view, so that assignments to these, such as </p>
  
  <pre><code>df.iloc[3] = 70
  </code></pre>
  
  <p>or </p>
  
  <pre><code>df.ix[1,'B':'E'] = 222
  </code></pre>
  
  <p>will change <code>df</code>. But I'm lost when it comes to more complicated cases. For example, </p>
  
  <pre><code>df[df.C &lt;= df.B] = 7654321
  </code></pre>
  
  <p>changes <code>df</code>, but</p>
  
  <pre><code>df[df.C &lt;= df.B].ix[:,'B':'E']
  </code></pre>
  
  <p>does not.</p>
  
  <p>Is there a simple rule that Pandas is using that I'm just missing? What's going on in these specific cases; and in particular, how do I change all values (or a subset of values) in a dataframe that satisfy a particular query (as I'm attempting to do in the last example above)?</p>
  
  <hr>
  
  <p>Note: This is not the same as <a href="https://stackoverflow.com/q/17960511/656912">this question</a>; and I have read <a href="http://pandas.pydata.org/pandas-docs/dev/indexing.html#returning-a-view-versus-a-copy" rel="noreferrer">the documentation</a>, but am not enlightened by it. I've also read through the "Related" questions on this topic, but I'm still missing the simple rule Pandas is using, and how I'd apply it to — for example — modify the values (or a subset of values) in a dataframe that satisfy a particular query.</p>