diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 28923f0fbf240..e734882486b14 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -4807,11 +4807,21 @@ def _gotitem(self, key, ndim, subset=None): def aggregate(self, func, axis=0, *args, **kwargs): axis = self._get_axis_number(axis) - # TODO: flipped axis result = None + if axis == 0: try: - result, how = self._aggregate(func, axis=0, *args, **kwargs) + result, how = self._aggregate(func, + _axis=0, + *args, **kwargs) + except TypeError: + pass + elif axis == 1: + try: + result, how = self.T._aggregate(func, + _axis=0, + *args, **kwargs) + result = result.T except TypeError: pass if result is None: diff --git a/pandas/tests/frame/test_apply.py b/pandas/tests/frame/test_apply.py index d1ad9f71e6350..cc07fae535723 100644 --- a/pandas/tests/frame/test_apply.py +++ b/pandas/tests/frame/test_apply.py @@ -1012,3 +1012,18 @@ def test_non_callable_aggregates(self): expected = df.size assert result == expected + + def test_frame_row_and_column_aggregates(self): + df = DataFrame({'B': [4, 5, 6, 7, 8], + 'C': [7, 8, 9, 10, 11]}, + index=[1, 2, 3, 4, 5]) + + assert_series_equal(df.agg('min', axis=1), + Series({1: 4, + 2: 5, + 3: 6, + 4: 7, + 5: 8})) + + assert_series_equal(df.agg('min', axis=1), + df.T.agg('min').T)