Pandas: update column values from another column if criteria [duplicate]
问题 This question already has answers here : Pandas conditional creation of a series/dataframe column (8 answers) Closed 2 years ago . I have a DataFrame: A B 1: 0 1 2: 0 0 3: 1 1 4: 0 1 5: 1 0 I want to update each item column A of the DataFrame with values of column B if value from column A equals 0. DataFrame I want to get: A B 1: 1 1 2: 0 0 3: 1 1 4: 1 1 5: 1 0 I've already tried this code df['A'] = df['B'].apply(lambda x: x if df['A'] == 0 else df['A']) It raise an error : The truth value of