pandas/rename-after-agg
| Rule | rename-after-agg |
|---|---|
| Pack | pandas |
| Severity | warning |
| Fix | none, edit by hand |
| Library versions | every version |
Renaming columns right after agg names them in a second step. Name them in agg itself, as in agg(b_mean=("b", "mean")).
summary = df.groupby("region").agg({"load": "mean"}).rename(columns={"load": "mean_load"})summary = df.groupby("region").agg(mean_load=("load", "mean"))What the rule reports
Section titled “What the rule reports”The rule reports g.agg({"b": "mean"}).rename(columns={"b": "b_mean"}).
How to fix it
Section titled “How to fix it”xpd has no automatic fix, so make the change by hand.
Message
Section titled “Message”xpd prints this message with the issue. A name that starts with $ stands for code from your file.
Name the result columns in agg itself, as in agg(b_mean=("b", "mean")), instead of renaming them afterwards.Browse the other rules of the pandas pack.