My original data frame is this
data = {'Patient_ID': ['A', 'B', 'C', 'D'], 'Vision_Difficulty': ['111', '111', '113', '114'],'Hearing_Difficulty': ['111', '111', '113', '114'], 'Hearing_Difficulty': ['112', '111', '112', '113'],'Moving_Difficulty': ['111', '111', '112', '111']}
df = pd.DataFrame(data)
It presents a set of patients and three types of difficulties. '111' indicates that the patient does not have any difficulties, whereas the other codes (112,113,114) indicates that they do.
What I want to do is I want to iterate over the three columns to find patients that have at least one type of difficulty and save the result to a new column "Difficulty_status" with (yes/no) values.
The desired output is as below
data = {'Patient_ID': ['A', 'B', 'C', 'D'], 'Vision_Difficulty': ['111', '111', '113', '114'],'Hearing_Difficulty': ['111', '111', '113', '114'], 'Hearing_Difficulty': ['112', '111', '112', '113'],'Moving_Difficulty': ['111', '111', '112', '111'], 'Difficulty_status':['yes','no','yes','yes']}
df_output = pd.DataFrame(data)
What I have achieved so far is this
df['Difficylty_status'] = ['yes' if x != '111' else 'no' for x in df['Vision_Difficulty']]
I want to generalize this code to check all three columns (Vision_Difficulty, Hearing_Difficulty, Moving_Difficulty)