python - The truth value of a Series is ambiguous -


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

for code, getting:

valueerror: truth value of series ambiguous. use a.empty, a.bool(), a.item(), a.any() or a.all().

maybe solve (our) problem.

import random import pandas pd import numpy np heart_rate = [random.randrange(45, 125) _ in range(500)] blood_pressure_systolic = [random.randrange(140, 230) _ in range(500)] blood_pressure_dyastolic = [random.randrange(90, 140) _ in range(500)] temperature = [random.randrange(34, 42) _ in range(500)] respiratory_rate = [random.randrange(8, 35) _ in range(500)] pulse_oximetry = [random.randrange(95, 100) _ 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") 

this 1 should work now.


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -