title: ipython pandas crosstab memory error
body: <p>I am new to ipython and pandas</p>
  
  <p>When I run <strong>pd.crosstab(df['A'], df['B'])</strong>. It has error <strong>MemoryError</strong></p>
  
  <p>The dataframe has 10,000,000 rows. I think maybe the size of data is too large.</p>
  
  <p>I check the size of dataframe with <strong>df.values.nbytes + df.index.nbytes + df.columns.nbytes</strong></p>
  
  <p>The memory is only <strong>381 MB</strong>. My server has <strong>16GB ram</strong></p>
  
  <p>If I run the dataframe with 1,000,000 rows, there is no problem.</p>
  
  <p>I hope someone can help.</p>
  
  <p><em>The debug log for error:</em></p>
  
  <pre><code>---------------------------------------------------------------------------
  MemoryError                               Traceback (most recent call last)
  &lt;ipython-input-6-199f99c3064f&gt; in &lt;module&gt;()
       99 df = df.applymap(lambda x: np.nan if str(x) == "N/A" or len(str(x).strip()) == 0 else x)
      100 
  --&gt; 101 summary_table(df)
  
  &lt;ipython-input-6-199f99c3064f&gt; in summary_table(df)
       78     dis_for_cont_vars(df)
       79 
  ---&gt; 80     value_count(df)
       81 #END summary_table
       82 
  
  &lt;ipython-input-6-199f99c3064f&gt; in value_count(df)
       63 def value_count(df):
       64     print "===&gt; Value counts\n"
  ---&gt; 65     print pd.crosstab(df['A'], df['B'])
       66     print "===&gt;\n"
       67 
  
  /home/deploy/anaconda/lib/python2.7/site-packages/pandas/tools/pivot.pyc in crosstab(rows, cols, values, rownames, colnames, aggfunc, margins, dropna)
      368         df['__dummy__'] = 0
      369         table = df.pivot_table('__dummy__', rows=rownames, cols=colnames,
  --&gt; 370                                aggfunc=len, margins=margins, dropna=dropna)
      371         return table.fillna(0).astype(np.int64)
      372     else:
  
  /home/deploy/anaconda/lib/python2.7/site-packages/pandas/tools/pivot.pyc in pivot_table(data, values, rows, cols, aggfunc, fill_value, margins, dropna)
      108         to_unstack = [agged.index.names[i]
      109                       for i in range(len(rows), len(keys))]
  --&gt; 110         table = agged.unstack(to_unstack)
      111 
      112     if not dropna:
  
  /home/deploy/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in unstack(self, level)
     3211         """
     3212         from pandas.core.reshape import unstack
  -&gt; 3213         return unstack(self, level)
     3214 
     3215     #----------------------------------------------------------------------
  
  /home/deploy/anaconda/lib/python2.7/site-packages/pandas/core/reshape.pyc in unstack(obj, level)
      416 def unstack(obj, level):
      417     if isinstance(level, (tuple, list)):
  --&gt; 418         return _unstack_multiple(obj, level)
      419 
      420     if isinstance(obj, DataFrame):
  
  /home/deploy/anaconda/lib/python2.7/site-packages/pandas/core/reshape.pyc in _unstack_multiple(data, clocs)
      316                           columns=data.columns)
      317 
  --&gt; 318         unstacked = dummy.unstack('__placeholder__')
      319         if isinstance(unstacked, Series):
      320             unstcols = unstacked.index
  
  /home/deploy/anaconda/lib/python2.7/site-packages/pandas/core/frame.pyc in unstack(self, level)
     3211         """
     3212         from pandas.core.reshape import unstack
  -&gt; 3213         return unstack(self, level)
     3214 
     3215     #----------------------------------------------------------------------
  
  /home/deploy/anaconda/lib/python2.7/site-packages/pandas/core/reshape.pyc in unstack(obj, level)
      420     if isinstance(obj, DataFrame):
      421         if isinstance(obj.index, MultiIndex):
  --&gt; 422             return _unstack_frame(obj, level)
      423         else:
      424             return obj.T.stack(dropna=False)
  
  /home/deploy/anaconda/lib/python2.7/site-packages/pandas/core/reshape.pyc in _unstack_frame(obj, level)
      459         unstacker = _Unstacker(obj.values, obj.index, level=level,
      460                                value_columns=obj.columns)
  --&gt; 461         return unstacker.get_result()
      462 
      463 
  
  /home/deploy/anaconda/lib/python2.7/site-packages/pandas/core/reshape.pyc in get_result(self)
      141         # TODO: find a better way than this masking business
      142 
  --&gt; 143         values, value_mask = self.get_new_values()
      144         columns = self.get_new_columns()
      145         index = self.get_new_index()
  
  /home/deploy/anaconda/lib/python2.7/site-packages/pandas/core/reshape.pyc in get_new_values(self)
      185         else:
      186             dtype, fill_value = _maybe_promote(values.dtype)
  --&gt; 187             new_values = np.empty(result_shape, dtype=dtype)
      188             new_values.fill(fill_value)
      189 
  
  MemoryError: 
  </code></pre>