I am trying to modify specific values in a column, where the modification uses values from another column. For example say I have a df:
A B C
1 3 8
1 6 8
2 2 9
2 6 1
3 4 5
3 6 7
Where I want df['B'] = df['B'] + df['C'] only for the subset df.loc[df['A'] == 2]
Producing:
A B C
1 3 8
1 6 8
2 11 9
2 7 1
3 4 5
3 6 7
I have tried
df.loc[(df['A']==2), 'B'].apply(lambda x: x + df['C'])
but get:
InvalidIndexError: Reindexing only valid with uniquely valued Index objects