Skip to content

calling mean on groupby of timedelta does not work #12440

Closed
@cancan101

Description

@cancan101

Code Sample, a copy-pastable example if possible

This works:

print pd.DataFrame([pd.Timedelta(1)]).groupby(level=0).sum()
                0
0 00:00:00.000000

but this does not:

print pd.DataFrame([pd.Timedelta(1)]).groupby(level=0).mean()
---------------------------------------------------------------------------
DataError                                 Traceback (most recent call last)
<ipython-input-151-ac23f5162583> in <module>()
----> 1 print pd.DataFrame([pd.Timedelta(1)]).groupby(level=0).mean()

/Users/alex/.virtualenvs/work/lib/python2.7/site-packages/pandas/core/groupby.pyc in mean(self)
    758         """
    759         try:
--> 760             return self._cython_agg_general('mean')
    761         except GroupByError:
    762             raise

/Users/alex/.virtualenvs/work/lib/python2.7/site-packages/pandas/core/groupby.pyc in _cython_agg_general(self, how, numeric_only)
   2851 
   2852     def _cython_agg_general(self, how, numeric_only=True):
-> 2853         new_items, new_blocks = self._cython_agg_blocks(how, numeric_only=numeric_only)
   2854         return self._wrap_agged_blocks(new_items, new_blocks)
   2855 

/Users/alex/.virtualenvs/work/lib/python2.7/site-packages/pandas/core/groupby.pyc in _cython_agg_blocks(self, how, numeric_only)
   2896 
   2897         if len(new_blocks) == 0:
-> 2898             raise DataError('No numeric types to aggregate')
   2899 
   2900         return data.items, new_blocks

DataError: No numeric types to aggregate

even though both of these work:

pd.DataFrame([pd.Timedelta(1)]).mean()

and

pd.DataFrame([pd.Timedelta(1)]).sum()

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 2.7.9.final.0
python-bits: 64
OS: Darwin
OS-release: 14.5.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.17.1
nose: 1.3.6
pip: 1.5.6
setuptools: 3.6
Cython: None
numpy: 1.10.4
scipy: 0.15.1
statsmodels: None
IPython: 3.1.0
sphinx: None
patsy: None
dateutil: 2.4.2
pytz: 2015.7
blosc: None
bottleneck: None
tables: None
numexpr: None
matplotlib: 1.4.3
openpyxl: None
xlrd: 0.9.3
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.4.0
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.11
pymysql: None
psycopg2: 2.6.1 (dt dec pq3 ext lo64)
Jinja2: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions