In pandas, can I deeply copy a DataFrame including its index and column?

pandas, python

Solution

Latest version of Pandas does not have this issue anymore

  import pandas as pd
  df = pd.DataFrame([[1], [2], [3]])

  df2 = df.copy(deep=True)

  id(df), id(df2)
  Out[3]: (136575472, 127792400)

  id(df.index), id(df2.index)
  Out[4]: (145820144, 127657008)

Problem

First, I create a DataFrame ``` In [61]: import pandas as pd In [62]: df = pd.DataFrame([[1], [2], [3]]) ``` Then, I deeply copy it by `copy` ``` In [63]: df2 = df.copy(deep=True) ``` Now the `DataFrame` are different. ``` In [64]: id(df), id(df2) Out[64]: (4385185040, 4385183312) ``` However, the `index` are still the same. ``` In [65]: id(df.index), id(df2.index) Out[65]: (4385175264, 4385175264) ``` Same thing happen in columns, is there any way that I can easily deeply copy it not only values but also index and columns?

Original source