Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agg method with list of functions does not work with axis=1 #16679

lafras opened this issue Jun 12, 2017 · 3 comments


None yet
3 participants
Copy link

commented Jun 12, 2017

Code Sample

import numpy
import pandas


frame = pandas.DataFrame(
    data=numpy.random.random((5, 3))
# Works
    frame.agg(['mean', 'std'])
# Expected output
    frame.transpose().agg(['mean', 'std']).transpose()
# Does not work as expected
    frame.agg(['mean', 'std'], axis=1)

Problem description

Calling the agg method on a frame with axis=1 raises a TypeError:

Traceback (most recent call last):
  File "/home/lafras/tmp/", line 13, in <module>
    frame.agg(['mean', 'std'], axis=1)
  File "/home/lafras/.local/lib/python3.5/site-packages/pandas/core/", line 4154, in aggregate
    return self.apply(func, axis=axis, args=args, **kwargs)
  File "/home/lafras/.local/lib/python3.5/site-packages/pandas/core/", line 4262, in apply
  File "/home/lafras/.local/lib/python3.5/site-packages/pandas/core/", line 4358, in _apply_standard
    results[i] = func(v)
TypeError: ("'list' object is not callable", 'occurred at index 0')

Expected Output

frame.agg(['mean', 'std'], axis=1) should produce this:

       mean       std
0  0.417119  0.216033
1  0.612642  0.294504
2  0.678825  0.357107
3  0.578248  0.267557
4  0.588805  0.189838

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: python-bits: 64 OS: Linux OS-release: 4.4.0-79-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_ZA.UTF-8 LOCALE: en_ZA.UTF-8

pandas: 0.20.2
pytest: 3.0.4
pip: 9.0.1
setuptools: 36.0.1
Cython: 0.25.2
numpy: 1.13.0
scipy: 0.19.0
xarray: 0.8.2
IPython: 6.1.0
sphinx: None
patsy: 0.4.1
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: 3.3.0
numexpr: 2.6.1
feather: None
matplotlib: 2.0.0
openpyxl: None
xlrd: 1.0.0
xlwt: None
xlsxwriter: None
lxml: None
bs4: 4.4.1
html5lib: 0.9999999
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.9.5
s3fs: 0.0.7
pandas_gbq: None
pandas_datareader: 0.2.1


This comment has been minimized.

Copy link

commented Jun 12, 2017

yeah looks like an under tested case. welcome for you to have a debugging look.

@jreback jreback added this to the Next Major Release milestone Jun 12, 2017


This comment has been minimized.

Copy link

commented Feb 7, 2018

Confirming that as of version 0.22.0 this issue still exists. A work around is to do: frame.T.agg([list_of_func]).T


This comment has been minimized.

Copy link

commented Feb 8, 2018

@spencerogden hence the 'open' tag. PR's to fix are welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.