title: pandas, dataframe, groupby, std
body: <p>New to pandas here. A (trivial) problem: hosts, operations, execution times. I want to group by host, then by host+operation, calculate std deviation for execution time per host, then by host+operation pair. Seems simple?</p>
  
  <p>It works for grouping by a single column:</p>
  
  <pre><code>df
  Out[360]:
  &lt;class 'pandas.core.frame.DataFrame'&gt;
  Int64Index: 132564 entries, 0 to 132563
  Data columns (total 9 columns):
  datespecial    132564  non-null values
  host           132564  non-null values
  idnum          132564  non-null values
  operation      132564  non-null values
  time           132564  non-null values
  ...
  dtypes: float32(1), int64(2), object(6)
  
  
  
  byhost = df.groupby('host')
  
  
  byhost.std()
  Out[362]:
                   datespecial         idnum      time
  host
  ahost1.test  11946.961952  40367.033852  0.003699
  host1.test   15484.975077  38206.578115  0.008800
  host10.test           NaN  37644.137631  0.018001
  ...
  </code></pre>
  
  <p>Nice. Now:</p>
  
  <pre><code>byhostandop = df.groupby(['host', 'operation'])
  
  byhostandop.std()
  ---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-364-2c2566b866c4&gt; in &lt;module&gt;()
  ----&gt; 1 byhostandop.std()
  
  /home/username/anaconda/lib/python2.7/site-packages/pandas/core/groupby.pyc in std(self, ddof)
      386         # todo, implement at cython level?
      387         if ddof == 1:
  --&gt; 388             return self._cython_agg_general('std')
      389         else:
      390             f = lambda x: x.std(ddof=ddof)
  
  /home/username/anaconda/lib/python2.7/site-packages/pandas/core/groupby.pyc in _cython_agg_general(self, how, numeric_only)
     1615
     1616     def _cython_agg_general(self, how, numeric_only=True):
  -&gt; 1617         new_blocks = self._cython_agg_blocks(how, numeric_only=numeric_only)
     1618         return self._wrap_agged_blocks(new_blocks)
     1619
  
  /home/username/anaconda/lib/python2.7/site-packages/pandas/core/groupby.pyc in _cython_agg_blocks(self, how, numeric_only)
     1653                 values = com.ensure_float(values)
     1654
  -&gt; 1655             result, _ = self.grouper.aggregate(values, how, axis=agg_axis)
     1656
     1657             # see if we can cast the block back to the original dtype
  
  /home/username/anaconda/lib/python2.7/site-packages/pandas/core/groupby.pyc in aggregate(self, values, how, axis)
      838                 if is_numeric:
      839                     result = lib.row_bool_subset(result,
  --&gt; 840                                                  (counts &gt; 0).view(np.uint8))
      841                 else:
      842                     result = lib.row_bool_subset_object(result,
  
  /home/username/anaconda/lib/python2.7/site-packages/pandas/lib.so in pandas.lib.row_bool_subset (pandas/lib.c:16540)()
  
  ValueError: Buffer dtype mismatch, expected 'float64_t' but got 'float'
  </code></pre>
  
  <p>Huh?? Why do I get this exception? </p>
  
  <p>More questions: </p>
  
  <ul>
  <li><p>how do I calculate std deviation on <code>dataframe.groupby([several columns])</code>?</p></li>
  <li><p>how can I limit calculation to a selected column? E.g. it obviously doesn't make sense to calculate std dev on dates/timestamps here.</p></li>
  </ul>