title: Checking whether data frame is copy or view in Pandas
body: <p>Is there an easy way to check whether two data frames are different copies or views of the same underlying data that doesn't involve manipulations? I'm trying to get a grip on when each is generated, and given how idiosyncratic the rules seem to be, I'd like an easy way to test. </p>
  
  <p>For example, I thought "id(df.values)" would be stable across views, but they don't seem to be:</p>
  
  <pre><code># Make two data frames that are views of same data.
  df = pd.DataFrame([[1,2,3,4],[5,6,7,8]], index = ['row1','row2'], 
         columns = ['a','b','c','d'])
  df2 = df.iloc[0:2,:]
  
  # Demonstrate they are views:
  df.iloc[0,0] = 99
  df2.iloc[0,0]
  Out[70]: 99
  
  # Now try and compare the id on values attribute
  # Different despite being views! 
  
  id(df.values)
  Out[71]: 4753564496
  
  id(df2.values)
  Out[72]: 4753603728
  
  # And we can of course compare df and df2
  df is df2
  Out[73]: False
  </code></pre>
  
  <p>Other answers I've looked up that try to give rules, but don't seem consistent, and also don't answer this question of how to test:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/23296282/what-rules-does-pandas-use-to-generate-a-view-vs-a-copy">What rules does Pandas use to generate a view vs a copy?</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/17960511/pandas-subindexing-dataframes-copies-vs-views">Pandas: Subindexing dataframes: Copies vs views</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/14192741/understanding-pandas-dataframe-indexing">Understanding pandas dataframe indexing</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/22537112/re-assignment-in-pandas-copy-or-view">Re-assignment in Pandas: Copy or view?</a></p></li>
  </ul>
  
  <p>And of course: 
   - <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#returning-a-view-versus-a-copy" rel="noreferrer">http://pandas.pydata.org/pandas-docs/stable/indexing.html#returning-a-view-versus-a-copy</a></p>
  
  <p><strong>UPDATE:</strong> Comments below seem to answer the question -- looking at the <code>df.values.base</code> attribute rather than <code>df.values</code> attribute does it, as does a reference to the <code>df._is_copy</code> attribute (though the latter is probably very bad form since it's an internal).</p>