0

I have df that currently has two columns df[['sys1','dia1']]

I created this function (the parameters are d= df['dia1'] and s = df['sys1'] :

Now i am trying to create a third column by using this function. It would look like this:

df['FirstVisitStge'] = df['FirstVisitStge'].apply(classify)

I am getting an error. I even tried using predefined parameters in the function and still getting an error. What am i doing wrong?

def classify(d,s):
    if (d>=90 & d<100 & s<160) or (s >= 140 & s < 160 & d < 100):
        return 'Stage 1'
    elif (s >= 160 & s <180 & d <110) or (d >= 100 and d < 110 and s > 180):
        return 'Stage 2'
    elif s >= 180 or d >= 110:
        return 'hypertensive crisis'
    else:
        return 'NA'

Bob
  • 23
  • 2
  • The way you're creating the third column is not correct. You can rather do `df.apply(classify)` and handle your columns with your `classify` function – Irfanuddin Feb 02 '22 at 19:02
  • Does this answer your question? [How to apply a function to two columns of Pandas dataframe](https://stackoverflow.com/questions/13331698/how-to-apply-a-function-to-two-columns-of-pandas-dataframe) – Irfanuddin Feb 02 '22 at 19:05
  • i cannot get this to work....not sure what else to do anymore – Bob Feb 02 '22 at 19:51
  • What is the error you get? – Irfanuddin Feb 02 '22 at 19:57
  • boolean operator error but i am not even sure if i am implementing correctly what you are suggesting above – Bob Feb 02 '22 at 20:04
  • I solved it. thanks for your help. the links that you shared helped a lot – Bob Feb 02 '22 at 21:20

0 Answers0