Skip to content
5 changes: 4 additions & 1 deletion pandas/core/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,10 @@ def agg_dict_like(
elif (
isinstance(selected_obj, ABCDataFrame) and k not in selected_obj.columns
):
raise KeyError(f"Column '{k}' does not exist!")
if is_list_like(k):
for c in k:
if c not in selected_obj.columns:
raise KeyError(f"Column '{c}' does not exist!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should probably have else clause.

else: raise KeyError(f"Column '{k}' does not exist!") 
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point, added. Thanks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would you think of :

not_found = [c for c in k if c not in selected_obj.columns] raise KeyError(f"Column(s) {', '.join(not_found)} do(es) not exist!")

arg = new_arg

Expand Down