My boosting_df Pandas DataFrame is as follows:
sku boost1 boost2 boost3 boost4
0 a ffffdfg a fggg replace
1 b fff fff fff replace
2 c ddf b ddf replace
3 d dfgd dfgd d replace
for each line, if the "sku" value matches the value of boost1 or boost2 or boost3, then I want to replace the match value with the value inside boost4
Example:
sku boost1 boost2 boost3
0 a ffffdfg replace fggg
1 b fff fff fff
2 c ddf b ddf
3 d dfgd dfgd replace
I tried:
boosting_df.loc[boosting_df['boost1'] == boosting_df['sku'], 'boost1'] = boosting_df['boost4']
boosting_df.loc[boosting_df['boost2'] == boosting_df['sku'], 'boost2'] = boosting_df['boost4']
boosting_df.loc[boosting_df['boost2'] == boosting_df['sku'], 'boost3'] = boosting_df['boost4']
But I got the following error:
ValueError: shape mismatch: value array of shape (4,) could not be broadcast to indexing result of shape (0,)
source
share