first time here, just started learning to code, I am conducting a clinical study regarding some risk factors of a disease, here I already got an excel of patient data. The purpose of the code is to count the number of risk factors(obesity, hypertension, diabetes, hyperlipidemia) of each patient(each row), and print the result in a new column, and the last step, count the number of how many patients have total 4 risk factors, and how many have 3, 2 and only one, or none.
date frame is something like this(just an example, not breaking confidentiality): part of the dataframe
well, try this part in python, just made it up, and I tried the following code:
import pandas as pd
df1=pd.DataFrame({'gender':['male','male','female','female','male'],'age':[49,60,65,20,65],
'obesity':['yes','yes','NaN','NaN','yes'],
'hypertension':['yes','yes','yes','NaN','yes'],
'diabetes':['NaN','yes','NaN','NaN','yes'],
'hyperlipidemia':['yes','yes','yes','NaN','NaN']})
factor_count=[] #to be written in the very right column
row=0
column=3
while row<=5: #5 rows in total for this example
count=0 #to count the risk factors of each row
while column<=5:
if df.iloc[row,column] == 'yes': #probably my while loop is really stupid
count+=1
column+=1
factor_count.append(count)
row+=1
print(factor_count)
well, after I hit run, the kernel never stops, I just learned to program on my own, hence I have no idea what happened, so I had to terminate the kernel. Can someone help me with this?