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 a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().