I’m trying to practice coding again and currently having problems with figuring out why my function doesn’t work.
Here’s my sample Table for reference:
diastolic | systolic |
---|---|
80.0 | 130.0 |
77.0 | 126.0 |
92.0 | 152.0 |
76.0 | 147.0 |
70.0 | 127.0 |
64.0 | 119.0 |
72.0 | 135.0 |
84.0 | 137.0 |
85.0 | 165.0 |
81.0 | 156.0 |
and here’s the function I created to categorize the data:
def blood_pressure_cat(diastolic, systolic):
"""
diastolic: float
systolic: float
"""
if systolic <= 90 and diastolic <= 60:
return "Hypotension"
elif systolic < 120 and diastolic < 80:
return "Normal"
elif systolic < 130 and diastolic < 80:
return "Elevated"
elif systolic < 140 and diastolic < 90:
return "Stage 1"
elif systolic < 180 and diastolic < 90:
return "Stage 2"
elif systolic >= 180 and diastolic >= 90:
return "Hypertensive Crisis"
else:
return np.nan
This is how I execute my function:
blood_pressure_cat(DF["diastolic"], DF["systolic"])
And getting this error:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
If I change the “and”s in that function I get this one instead:
Cannot perform 'rand_' with a dtyped [float64] array and scalar of type [bool]
Can somebody help me understand why it is not working or if there’s any alternative way to run this code?