I am needing to create a list for patients in a df that classifies them as 'high', 'medium', or 'low' depending on their BMI and if they smoke. When I current run the code, I am getting 'Medium' for all six entries. (Pseudo names and data have been used)
df = pd.DataFrame({'Name':['Jordan', 'Jess', 'Jake', 'Alice', 'Alan', 'Lauren'],
'Age':[26, 23, 19, 20, 24, 28],
'Sex':['M', 'F' , 'M', 'F', 'M', 'F'],
'BMI':[26, 22, 24, 17, 35, 20],
'Smokes':['No', 'No', 'Yes', 'No', 'Yes', 'No']})
risk_list = []
for i in df.Name:
if df.BMI.any() > 30 | df.BMI.any() < 19.99 | df.Smokes.any() == "Yes":
risk_list.append("High")
elif df.BMI.any() >= 25 & df.BMI.any() <= 29.99:
risk_list.append("Medium")
elif df.BMI.any() < 24.99 & df.BMI.any() > 19.99 and df.Smokes.any() == "No":
risk_list.append("Low")
print(risk_list)
Output:
['Medium', 'Medium', 'Medium', 'Medium', 'Medium', 'Medium']
I am new to pandas and python for that matter. I think I am close but cannot figure out why my data is not being returned correctly.
Thanks.