79169784

Date: 2024-11-08 11:17:41
Score: 1
Natty:
Report link

I'm only four years late here and can't comment yet, so adding this as an answer.

It's probably the newer Python & Pandas causing this but this now fires Assertion Error, as the .groupby adds the grouping key to the output.

df["cagr"] = df.groupby("company").apply(lambda x, period: ((x.pct_change(period) + 1) ** (1/period)) - 1, cagr_period)

Simple fix to this is to use group_keys=False

df["cagr"] = df.groupby("company", group_keys=False).apply(lambda x, period: ((x.pct_change(period) + 1) ** (1/period)) - 1, cagr_period)
Reasons:
  • RegEx Blacklisted phrase (1): can't comment
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Arseni