I have a dataframe similar to the one below, in which activities assume binary values representing whether they require a doctor:
d = {'activity': ['Check-up', 'Assessment', 'Medication', 'Medication', 'Medication'], 'doctor_requirement': [1, 0,0,0,0]}
df = pd.DataFrame(data=d)
df
activity doctor_requirement
0 Check-up 1
1 Assessment 0
2 Medication 0
3 Medication 0
4 Medication 0
I would like to consider that a percentage of 'Medication' activities require a doctor. That is, to assign binary 1 to doctor_requirement for a percentage of 'Medication' visits. For instance, such that 50% of the activity 'Medication' requires a doctor (i.e. doctor_requirement = 1).
I would greatly appreciate your help, I've been looking online and can't seem to find how to apply such a condition. Thanks in advance!