How can I fix this code where I'm trying to assign the values in a column according to the various conditions. Writing the below code gives me an error saying:
The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
list = [df1,df2,df3,df4] # multiple dataframes
grp_list = ["con", "eco", "dip", "pol"] # multiple categories in a column
for i in list:
if i['pgp'].isin(group_list) and (i.egp == i.pgp):
i['value'] == 1
elif ~i['pgp'].isin(group_list):
i['value'] == 2
else:
i['value'] == 0
Expected Output df1:
pgp egp value
con con 1 # return 1 if pgp value is in the element list & pgp = egp
eco eco 1
dip health 0 # else 0
pol health 0
god con 2
ent eco 2 # return 2 if pgp value is not in the element list