Issue 1:
Using the built-in sum function gives correct result in df.agg(sum, axis=0), but wrong result in df.agg(sum, axis=1).

>>> df = pd.DataFrame([[np.nan, 2], [3, 4]])
>>> df.agg(sum, axis=0)
0 3.0
1 6.0
dtype: float64
>>> df.agg(sum, axis=1)
0 NaN
1 7.0
dtype: float64

The NaN in the last example should be 2.0.

Also, operation using the builtin sum in agg with axis=1 are very slow:

>>> n = 1_000
>>> df = pd.DataFrame({'a': range(n), 'b': range(n)})
>>> %timeit df.agg(sum, axis=1)
16.5 ms ± 25.5 µs per loop (mean ± std. dev. of 7 runs, 100 loops each)
>>> %timeit df.T.agg(sum) # correct result *and* faster
312 µs ± 3.17 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

Problem description

Currently, df.agg(func, axis=1) defers to df.apply(func, axis=1). This is not done for axis=0, and the operation may therefore give unexpected results and slow the operation down (because df.apply can be very slow).

Expected Output

The expected output is:

>>> df.agg(sum, axis=1)
0 2.0
1 7.0
dtype: float64

Solution proposal

I'm thinking about putting in df.T.agg(func, axis=0) rather than df.apply(func, axis=1) in a few strategic places. This should ensure both getting correct results and faster operations. will report back if this succeeds.

Issue 2:
Code Sample

import numpy
import pandas

numpy.random.seed(1234)

frame = pandas.DataFrame(
data=numpy.random.random((5, 3))
)
print(
frame
)
# Works
print(
frame.agg(['mean', 'std'])
)
# Expected output
print(
frame.transpose().agg(['mean', 'std']).transpose()
)
# Does not work as expected
print(
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/buggy.py", line 13, in <module>
frame.agg(['mean', 'std'], axis=1)
File "/home/lafras/.local/lib/python3.5/site-packages/pandas/core/frame.py", line 4154, in aggregate
return self.apply(func, axis=axis, args=args, **kwargs)
File "/home/lafras/.local/lib/python3.5/site-packages/pandas/core/frame.py", line 4262, in apply
ignore_failures=ignore_failures)
File "/home/lafras/.local/lib/python3.5/site-packages/pandas/core/frame.py", 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: 3.5.2.final.0
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