Pandas: Change values chosen by boolean indexing in a column without getting a warning
问题 I have a dataframe, I want to change only those values of a column where another column fulfills a certain condition. I'm trying to do this with iloc at the moment and it either does not work or I'm getting that annoying warning: A value is trying to be set on a copy of a slice from a DataFrame Example: import pandas as pd DF = pd.DataFrame({'A':[1,1,2,1,2,2,1,2,1],'B':['a','a','b','c','x','t','i','x','b']}) Doing one of those DF['B'].iloc[:][DF['A'] == 1] = 'X' DF.iloc[:]['B'][DF['A'] == 1]