Replace values in DataFrame column when they start with string using lambda
问题 I have a DataFrame: import pandas as pd import numpy as np x = {'Value': ['Test', 'XXX123', 'XXX456', 'Test']} df = pd.DataFrame(x) I want to replace the values starting with XXX with np.nan using lambda. I have tried many things with replace, apply and map and the best I have been able to do is False, True, True, False. The below works, but I would like to know a better way to do it and I think the apply, replace and a lambda is probably a better way to do it. df.Value.loc[df.Value.str