import random
import pandas as pd
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}
df = pd.DataFrame(vitalsign)
df.to_csv('vitalsign.csv')
mask = (50 < df['heart rate'] < 101 &
140 < df['systolic blood pressure'] < 160 &
90 < df['dyastolic blood pressure'] < 100 &
35 < df['temperature'] < 39 &
11 < df['respiratory rate'] < 19 &
95 < df['pulse oximetry'] < 100
, "excellent", "critical")
df.loc[mask, "class"]
似乎是这样的,
我收到的错误信息:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()
如何解决它?
a < b < c
的链式比较,原因与你需要使用&
代替and
一样。 - user2357112