I am a newbie to Python. I am trying to create a new variable based on two columns in the dataset.
def cal_freqw(var1, var2):
    if var1 == 1:
        return 0
    elif (var1 == 2 and var2 < 998):
        return 7*var2
    elif var == 3:
        return var2/31;
    elif var1 == 98:
        return 9998
    elif var2 == 998:
        return 9998
df["FREQW"]=cal_freqw(df["UNIT"], df["NUM"])
I get this error message:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
 
df["UNIT"] and df["NUM"] are integers.(Correction: series of integers)
Because I have several variables like "UNIT" and "NUM" to be computed, a function would help. Could someone help me to fix my calling command? Thank you!
After editing my code suggested by Zichzheng and others, I still receive this following error message:
      2
      3 def cal_freqw(var1, var2):
----> 4     if var1 == 1:
      5         return 0
      6     elif (var1 == 2 & var2 < 998):
 
   1477               1     2
   1478         0  10.0  20.0
-> 1479         >>> df.equals(different_data_type)
   1480         False
   1481         """
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Thank you for your help!
 
    