Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8329569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T01:50:11+00:00 2026-06-09T01:50:11+00:00

I’m having a pandas Series object filled with decimal numbers of dtype Decimal. I’d

  • 0

I’m having a pandas Series 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:

resampled = ts.resample('D', how = 'mean')

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.

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.

How use the mean method on a pandas TimeSeries with Decimal type values?

Any idea how to solve this?

Here is the complete ipython session creating the error:

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\<ipython-input-45-09c898403ddd> in <module>()
----> 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)
--> 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):
---> 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) < len(axlabels) or self.how is not None:
    185                 grouped  = obj.groupby(grouper, axis=self.axis)
--> 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):
-> 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:
--> 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:
--> 378             raise GroupByError('No numeric types to aggregate')
    379
    380         return self._wrap_aggregated_output(output, names)

GroupByError: No numeric types to aggregate

Any help is appreciated.
Thanks,
Thomas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T01:50:13+00:00Added an answer on June 9, 2026 at 1:50 am

    I found the answer by myself. It is possible to provide a function to the ‘how’ argument of resample:

    f = lambda x: Decimal(np.mean(x))
    ts.resample('D', how = f)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want use html5's new tag to play a wav file (currently only supported
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.