Editing Original DataFrame After Making a Copy but Before Editing the Copy Changes the Copy <p>I am trying to understand how copying a pandas data frame works. When I assign a copy of an object in python I am not used to changes to the original object affecting copies of that object. For example:</p> <pre><code>x = 3 y = x x = 4 print(y) 3 </code></pre> <p>While <code>x</code> has subsequently been changed, y remains the same. In contrast, when I make changes to a pandas <code>df</code> after assigning it to a copy <code>df1</code> the copy is also affected by changes to the original DataFrame.</p> <pre><code>import pandas as pd import numpy as np def minusone(x): return int(x) - 1 df = pd.DataFrame({"A": [10,20,30,40,50], "B": [20, 30, 10, 40, 50], "C": [32, 234, 23, 23, 42523]}) df1 = df print(df1['A']) 0 10 1 20 2 30 3 40 4 50 Name: A, dtype: int64 df['A'] = np.vectorize(minusone)(df['A']) print(df1['A']) 0 9 1 19 2 29 3 39 4 49 Name: A, dtype: int64 </code></pre> <p>The solution appears to be making a deep copy with <code>copy.deepcopy()</code>, but because this behavior is different from the behavior I am used to in python I was wondering if someone could explain what the reasoning behind this difference is or if it is a bug.</p>