'Rename Pandas .agg() columns inside function call
Is there a way to do the following inside the .agg() function?
hl = df[["sym", "bid", "ask"]].groupby("sym").agg(["min", "max"])
hl = hl.rename(columns={"min": "low", "max": "high"})
I see from the pandas documentation that you can use pd.namedAgg to apply different aggregations to different columns but all I would like to do is rename the columns in the original .agg() call.
I am used to writing in a very terse language (kdb+/q) hence wanted to reduce the number of lines of code.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
