I have a dataframe with 2 columns and if certain condition is satisfied I want to perform certain operation on the dataframe. I came up with like below (dummy data):
raw_data = {'first_name': ['Jason', 'Molly', np.nan, np.nan, np.nan],
'nationality': ['USA', 'USA', 'France', 'UK', 'UK'],
'age': [42, 52, 36, 24, 70]}
df = pd.DataFrame(raw_data, columns = ['first_name', 'nationality', 'age'])
if df[df['first_name'].notnull() & (df['nationality'] == "USA")]:
# go ahead
But I am getting the value error:
ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Can someone point me what I am doing wrong with the if condition
Aucun commentaire:
Enregistrer un commentaire