Skip to content

Commit c0ca275

Browse files
committed
Avoid reiterating
1 parent 27e991a commit c0ca275

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

pandas/core/apply.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -480,20 +480,14 @@ def compute_dict_like(
480480
cols = df[key]
481481

482482
if cols.ndim == 1:
483-
series_list = [obj._gotitem(key, ndim=1, subset=cols)]
483+
series = obj._gotitem(key, ndim=1, subset=cols)
484+
results.append(getattr(series, op_name)(how, **kwargs))
485+
keys.append(key)
484486
else:
485-
series_list = []
486-
for index in range(cols.shape[1]):
487-
col = cols.iloc[:, index]
488-
487+
for _, col in cols.items():
489488
series = obj._gotitem(key, ndim=1, subset=col)
490-
series_list.append(series)
491-
492-
for series in series_list:
493-
result = getattr(series, op_name)(how, **kwargs)
494-
results.append(result)
495-
keys.append(key)
496-
489+
results.append(getattr(series, op_name)(how, **kwargs))
490+
keys.append(key)
497491
else:
498492
results = [
499493
getattr(obj._gotitem(key, ndim=1), op_name)(how, **kwargs)

0 commit comments

Comments
 (0)