79294692

Date: 2024-12-19 15:00:02
Score: 1
Natty:
Report link

One solution with apply() which runs a given function on each row:

df = df.replace("Unk", np.nan)
df["A1"] = df.apply(lambda row: round(row["A"] / dic["A_" + str(row.name)[:4]], 3) , axis=1)
df["B1"] = df.apply(lambda row: round(row["B"] / dic["B_" + str(row.name)[:4]], 3) , axis=1)
display(df)

enter image description here

PS: row is a series and row.name is actually the index of the dataframe so the date.

Reasons:
  • Probably link only (1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: rehaqds