79304528

Date: 2024-12-24 00:52:03
Score: 1
Natty:
Report link

You can define the mask with your 2 conditions and then use .loc:

x, y = 1, 5
mask = df["col1"].isin(["val2", "val3"]) & df.index.isin(range(x, y+1))
df.loc[mask, "col1"] = "val4"
display(df)

res

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