Checking whether data frame is copy or view in Pandas

前端 未结 3 663
别跟我提以往
别跟我提以往 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:29

    You might trace the memory your pandas/python environment is consuming, and, on the assumption that a copy will utilise more memory than a view, be able to decide one way or another.

    I believe there are libraries out there that will present the memory usage within the python environment itself - e.g. Heapy/Guppy.

    There ought to be a metric you can apply that takes a baseline picture of memory usage prior to creating the object under inspection, then another picture afterwards. Comparison of the two memory maps (assuming nothing else has been created and we can isolate the change is due to the new object) should provide an idea of whether a view or copy has been produced.

    We'd need to get an idea of the different memory profiles of each type of implementation, but some experimentation should yield results.

提交回复
热议问题