title: Optimal way to manage data cleaning data in pandas
body: <p>Prior to subsequent analysis I clean my data using the pandas library. Normally I make lots of small functions which do specific tasks:</p>
  
  <pre><code>def clean_str_columns(df, column):
      # do something to the dataframe
      df[column] = df[column].str.strip()
      # do more things
      return df
  </code></pre>
  
  <p>and then call them :</p>
  
  <pre><code>df = clean_str_columns(df, 'column_name')
  </code></pre>
  
  <p>If I am correct, when I pass the <code>df</code> to the function it makes a local reference to the <code>df</code> object which means this should give equivalent results:</p>
  
  <pre><code>def clean_str_columns(df, column):
      # do something to the dataframe
      df[column] = df[column].str.strip()
      # do more things
  </code></pre>
  
  <p>then: </p>
  
  <pre><code>clean_str_columns(df, 'column_name')
  </code></pre>
  
  <p>and the df object will be edited so my global reference will point to the edited object. </p>
  
  <p>What is the 'best style' when editing such dfs in place? </p>
  
  <p>I am primarily concerned with this because when I am working with lots of functions and cleaning a large <code>df</code> I often get a <code>MemoryError</code>. I keep track of my variables with the %who IPython magic and there are no stray ones and regularly run the Python garbage collector. My <code>df</code> is getting smaller (dropping rows and columns) yet I still get this error. So I am concerned that this issue is related to me re-assigning the global reference to the <code>df</code> multiple times?</p>