Checking whether data frame is copy or view in Pandas

前端 未结 3 660
别跟我提以往
别跟我提以往 2020-12-07 16:38

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 gri

3条回答
  •  北海茫月
    2020-12-07 17:32

    Answers from HYRY and Marius in comments!

    One can check either by:

    • testing equivalence of the values.base attribute rather than the values attribute, as in:

      df.values.base is df2.values.base instead of df.values is df2.values.

    • or using the (admittedly internal) _is_view attribute (df2._is_view is True).

    Thanks everyone!

提交回复
热议问题