I want to replace all "No" from a data frame col. but if col consists for any other string like "No error" then it will remain as it is.
test = ["No","No Error"]
data = pd.DataFrame(test, columns=["text"])
for i in range(len(data["text"])):
if len(data["text"][i]) == 2:
data["text"][i] = data["text"][i]).str.replace("No", "Data not available", regex=True)
else:
pass
print(data)
I'm getting an error while running the code. I'm able to get the result by using np.where but I've had several other criteria for conditional replace where "np.where" won't work. If I can make the above approach work it'll be great. Any help is greatly appreciated.
"No"in cells which contain a string that is exactly 2 characters long. Remove this condition and it works.