Copying and Modifying a Dataframe Pandas
<p>I have 3 Dataframes df1,df,df3 all copying an original Dataframe df0.</p>

<pre><code>df1=df0
df2=df0
df3=df0

df1=dfo.iloc[1:,1:].div(dfo.iloc[1:,1:].sum(axis=1),axis=0)
df2=dfo.iloc[1:,1:].div(dfo.iloc[1:,1:].sum(axis=1),axis=0)*ACCOUNT_CASH
df3=df2//df0

print(df1)
print(df2)
print(df3)
</code></pre>

<p>Somehow this does not work, I get no error but when I Print df1 df2 df3 all my dataframes are the same! However they're different from df0.Is it because they all point to the same space in memory, and so changing any pointer actually modifies all variables? If so how can I make it work well. I tried copy(deep=True) with unconclusive results. Thanks</p>

<p>Your lines </p>

<pre><code>df1=df0
df2=df0
df3=df0
</code></pre>

<p>simply create three new bindings, where three new names refer to <em>the same object</em> as that bound to by <code>df0</code>. </p>

<p>To actually create copies, use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.copy.html" rel="nofollow"><code>pd.DataFrame.copy</code></a>:</p>

<pre><code>df1=df0.copy()
df2=df0.copy()
df3=df0.copy()
</code></pre>

python variables pointers pandas memory