首页 文章

系列的真值是模棱两可的

提问于
浏览
-1
df['class'] = np.where(((df['heart rate'] > 50) & (df['heart rate'] < 101 )) & ((df['systolic blood pressure'] > 140 & df['systolic blood pressure'] < 160)) & 
   ((df['dyastolic blood pressure'] > 90 & ['dyastolic blood pressure'] < 100 )) & ((df['temperature'] > 35 & df['temperature'] < 39 )) & 
   ((df['respiratory rate'] >11 & df ['respiratory rate'] <19)) & ((df['pulse oximetry' > 95] & df['pulse oximetry' < 100] )), "excellent", "critical")

对于这段代码,我得到:

ValueError:系列的真值是不明确的 . 使用a.empty,a.bool(),a.item(),a.any()或a.all() .

1 回答

  • 0

    也许这会解决你(我们)的问题 .

    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")
    

    这一个现在应该工作 .

相关问题