也許這將解決你的(我們的)問題。
import random
import pandas as pd
import numpy as np
heart_rate = [random.randrange(45, 125) for _ in range(500)]
blood_pressure_systolic = [random.randrange(140, 230) for _ in range(500)]
blood_pressure_dyastolic = [random.randrange(90, 140) for _ in range(500)]
temperature = [random.randrange(34, 42) for _ in range(500)]
respiratory_rate = [random.randrange(8, 35) for _ in range(500)]
pulse_oximetry = [random.randrange(95, 100) for _ in range(500)]
vitalsign = {
'heart rate' : heart_rate,
'systolic blood pressure' : blood_pressure_systolic,
'dyastolic blood pressure' : blood_pressure_dyastolic,
'temperature' : temperature,
'respiratory rate' : respiratory_rate,
'pulse oximetry' : pulse_oximetry
}
vitalsign_maxima = {
'heart rate' : (50,101),
'systolic blood pressure' : (140,160),
'dyastolic blood pressure' : (90,100),
'temperature' : (35,39),
'respiratory rate' : (11,19),
'pulse oximetry' : (95,100)
}
def is_vitalsign_excellent(name):
lower, upper = vitalsign_maxima[name]
return (lower < df[name]) & (df[name] < upper)
df = pd.DataFrame(vitalsign)
f = np.where(is_vitalsign_excellent('heart rate') &
is_vitalsign_excellent('systolic blood pressure') &
is_vitalsign_excellent('dyastolic blood pressure') &
is_vitalsign_excellent('temperature') &
is_vitalsign_excellent('respiratory rate') &
is_vitalsign_excellent('pulse oximetry'),"excellent", "critical")
這一個應該現在工作。
對於此代碼我得到:噁心。 –
你打算使用一個按位''而不是一個布爾'和'? – James
'&'優先,你忘了一些括號。 – Julien