Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to resample a python pandas TimeSeries containing dytpe Decimal values?
    primarykey
    data
    text
    <p>I'm having a pandas <code>Series</code> object filled with decimal numbers of dtype Decimal. I'd like to use the new pandas 0.8 function to resample the decimal time series like this:</p> <pre><code>resampled = ts.resample('D', how = 'mean') </code></pre> <p>When trying this i get an "GroupByError: No numeric types to aggregate" error. I assume the problem is that np.mean is used internaly to resample the values and np.mean expects floats instead of Decimals. </p> <p>Thanks to the help of this forum i managed to solve a similar question using groupBy and the apply function but i would love to also use the cool resample function.</p> <p><a href="https://stackoverflow.com/questions/11459106/how-use-the-mean-method-on-a-pandas-timeseries-with-decimal-type-values">How use the mean method on a pandas TimeSeries with Decimal type values?</a></p> <p>Any idea how to solve this?</p> <p>Here is the complete ipython session creating the error:</p> <pre><code>In [37]: from decimal import Decimal In [38]: from pandas import * In [39]: rng = date_range('1.1.2012',periods=48, freq='H') In [40]: rnd = np.random.randn(len(rng)) In [41]: rnd_dec = [Decimal(x) for x in rnd] In [42]: ts = Series(rnd_dec, index=rng) In [43]: ts[0:3] Out[43]: 2012-01-01 00:00:00 -0.1020591335576267189022559023214853368699550628 2012-01-01 01:00:00 0.99245713975437366283216533702216111123561859130 2012-01-01 02:00:00 1.80080710727195758558139004890108481049537658691 Freq: H In [44]: type(ts[0]) Out[44]: decimal.Decimal In [45]: ts.resample('D', how = 'mean') --------------------------------------------------------------------------- GroupByError Traceback (most recent call last) C:\Users\THM\Documents\Python\&lt;ipython-input-45-09c898403ddd&gt; in &lt;module&gt;() ----&gt; 1 ts.resample('D', how = 'mean') C:\Python27\lib\site-packages\pandas\core\generic.pyc in resample(self, rule, how, axis, fill_method, closed, label, convention, kind, loffset, l imit, base) 187 fill_method=fill_method, convention=convention, 188 limit=limit, base=base) --&gt; 189 return sampler.resample(self) 190 191 def first(self, offset): C:\Python27\lib\site-packages\pandas\tseries\resample.pyc in resample(self, obj) 65 66 if isinstance(axis, DatetimeIndex): ---&gt; 67 rs = self._resample_timestamps(obj) 68 elif isinstance(axis, PeriodIndex): 69 offset = to_offset(self.freq) C:\Python27\lib\site-packages\pandas\tseries\resample.pyc in _resample_timestamps(self, obj) 184 if len(grouper.binlabels) &lt; len(axlabels) or self.how is not None: 185 grouped = obj.groupby(grouper, axis=self.axis) --&gt; 186 result = grouped.aggregate(self._agg_method) 187 else: 188 # upsampling shortcut C:\Python27\lib\site-packages\pandas\core\groupby.pyc in aggregate(self, func_or_funcs, *args, **kwargs) 1215 """ 1216 if isinstance(func_or_funcs, basestring): -&gt; 1217 return getattr(self, func_or_funcs)(*args, **kwargs) 1218 1219 if hasattr(func_or_funcs,'__iter__'): C:\Python27\lib\site-packages\pandas\core\groupby.pyc in mean(self) 290 """ 291 try: --&gt; 292 return self._cython_agg_general('mean') 293 except GroupByError: 294 raise C:\Python27\lib\site-packages\pandas\core\groupby.pyc in _cython_agg_general(self, how) 376 377 if len(output) == 0: --&gt; 378 raise GroupByError('No numeric types to aggregate') 379 380 return self._wrap_aggregated_output(output, names) GroupByError: No numeric types to aggregate </code></pre> <p>Any help is appreciated. Thanks, Thomas</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload