title: Memory leak in Pandas.groupby.apply()?
body: <p>I'm currently using Pandas for a project with csv source files of around 600mb. During the analysis I am reading in the csv to a dataframe, grouping on some column and applying a simple function to the grouped dataframe. I noticed that I was going into Swap Memory during this process and so carried out a basic test:</p>
  
  <p>I first created a fairly large dataframe in the shell:</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  df = pd.DataFrame(np.random.randn(3000000, 3),index=range(3000000),columns=['a', 'b', 'c'])
  </code></pre>
  
  <p>I defined a pointless function called do_nothing():</p>
  
  <pre><code>def do_nothing(group):
      return group
  </code></pre>
  
  <p>And ran the following command:</p>
  
  <pre><code>df = df.groupby('a').apply(do_nothing)
  </code></pre>
  
  <p>My system has 16gb of RAM and is running Debian (Mint). After creating the dataframe I was using ~600mb of RAM. As soon as the apply method began to execute, that value started to soar. It steadily climbed up to around 7gb(!) before finishing the command and settling back down to 5.4gb (while the shell was still active). The problem is, my work requires doing more than the 'do_nothing' method and as such while executing the real program, I cap my 16gb of RAM and start swapping, making the program unusable. Is this intended? I can't see why Pandas should need 7gb of RAM to effectively 'do_nothing', even if it has to store the grouped object.</p>
  
  <p>Any ideas on what's causing this/how to fix it? </p>
  
  <p>Cheers,</p>
  
  <p>.P</p>