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)