I'm trying to iterate over a data frame in python and in my if statement I reference a couple of columns that happen to be a Series. When i run my code I get the following error:
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Data:
Taken from solution provided by @CypherX.
template = ['some', 'abra', 'cadabra', 'juju', 'detail page', 'lulu', 'boo', 'honolulu', 'detail page']
prev = ['home', 'abra', 'cacobra', 'juju', 'detail page', 'lulu', 'booboo', 'picabo', 'detail here']
df = pd.DataFrame({'Template': template, 'Prev': prev})
Template Prev
0 some home
1 abra abra
2 cadabra cacobra
3 juju juju
4 detail page detail page
5 lulu lulu
6 boo booboo
7 honolulu picabo
8 detail page detail here
My code is the following:
for row in s:
if (s['Template']=='detail page') and (s['Template']==s['Prev']):
s['Swipe']=1
else:
s['Swipe']=0
where s
is my dataframe.
What can I do to fix this? Any ideas?