I have the following pandas dataframe:
import pandas as pd
import numpy as np
d = {'country' : ['us','uk','au','ca'],
'influencer' : [3000,304,100,10],
'platform' : [87,87,87,87]}
df = pd.DataFrame(d)
I am trying to add a new column 'influencer_updated' which is the conditional addition of 2 columns - influencer & platform based on different countries.
I have tried to solve the problem based on the below code snippet:
if df[(df['country'] == 'us')]:
df['influencer_updated'] = df['influencer'] + df['platform'] * 0.5
elif df[(df['country'] == 'uk') & (df['country'] == 'au')]:
df['influencer_updated'] = df['influencer'] + df['platform'] * 0.25
else:
df['influencer_updated'] = df['influencer']
The error I am getting is:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Please help!!