When I run this:
import pandas as pd
data = {'id': ['earn', 'earn','lose', 'earn'],
'game': ['darts', 'balloons', 'balloons', 'darts']
}
df = pd.DataFrame(data)
print(df)
print(df.loc[[1],['id']] == 'earn')
The output is:
id game
0 earn darts
1 earn balloons
2 lose balloons
3 earn darts
id
1 True
But when I try to run this loop:
for i in range(len(df)):
if (df.loc[[i],['id']] == 'earn'):
print('yes')
else:
print('no')
I get the error 'ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().' I am not sure what the problem is. Any help or advice is appreciated -- I am just starting.
I expected the output to be 'yes' from the loop. But I just got the 'ValueError' message. But, when I run the condition by itself, the output is 'True' so I'm not sure what is wrong.
dfthe same in both those examples?