diff --git a/pandas/core/apply.py b/pandas/core/apply.py index d024afa570a1e..5959156d11123 100644 --- a/pandas/core/apply.py +++ b/pandas/core/apply.py @@ -486,20 +486,14 @@ def compute_dict_like( cols = df[key] if cols.ndim == 1: - series_list = [obj._gotitem(key, ndim=1, subset=cols)] + series = obj._gotitem(key, ndim=1, subset=cols) + results.append(getattr(series, op_name)(how, **kwargs)) + keys.append(key) else: - series_list = [] - for index in range(cols.shape[1]): - col = cols.iloc[:, index] - + for _, col in cols.items(): series = obj._gotitem(key, ndim=1, subset=col) - series_list.append(series) - - for series in series_list: - result = getattr(series, op_name)(how, **kwargs) - results.append(result) - keys.append(key) - + results.append(getattr(series, op_name)(how, **kwargs)) + keys.append(key) else: results = [ getattr(obj._gotitem(key, ndim=1), op_name)(how, **kwargs)