Python & Pandas: Will using many df.copy affect code's performance?
<p>I'm doing some data analysis, and the data are in pandas <code>DataFrame</code>, <code>df</code>.</p>

<p>There are several function that I defined to do process on the <code>df</code>.</p>

<p>For encapsulation purpose, I define the functions like this:</p>

<pre><code>def df_process(df):
    df=df.copy()
    # do some process work on df
    return df
</code></pre>

<p>In Jupyter Notebook, I use the function as</p>

<pre><code>df = df_process(df)
</code></pre>

<p>The reason for using <code>df.copy()</code> is that otherwise the original <code>df</code> would be modified, whether you assign it back or not. (see <a href="https://stackoverflow.com/questions/38579921/python-pandas-how-to-return-a-copy-of-a-dataframe">Python &amp; Pandas: How to return a copy of a dataframe?</a>)</p>

<p>My question is:</p>

<ol>
<li><p>Is using <code>df=df.copy()</code> proper here? If not, how should a function handle data be defined?</p></li>
<li><p>Since I use several such data processing function, will it affect my program's performance? And how much?</p></li>
</ol>