I am new to programming and would appreciate your help. Trying to avoid repetition of code for querying on a pandas dataframe.
x1 is the dataframe with various column names such as Hypertension, Diabetes, Alcoholism, Handicap, Age_Group, Date_Appointment
Each of the disease column listed above contains 0 - not having disease, 2/3/4 - has different stages of disease
So when I filter on ' != 0 ' it will list records for patients with that specific disease. As such each disease will filter out different sets of records.
I wrote below query 4 times and replaced the word Hypertension with the other diseases to get 4 different graphs for each of the diseases.
But it is not clean coding. I need help to understand how any which function could be used and how to use it to write just 1 query instead of 4.
hyp1 = x1.query('Hypertension != 0')
i1 = hyp1.groupby('Age_Group')['Hypertension'].value_counts().plot(kind = 'bar',label = 'Hypertension',figsize=(6, 6))
plt.title('Appointments Missed by Patients with Hypertension')
plt.xlabel('Hypertension Age_Group')
plt.ylabel('Appointments missed');
Below is another set I don't know how to condense.
`print('Details of all appointments')
`print('')`
`print(df.Date_Appointment.value_counts().sort_index())`
`print('')`
`print(df.Date_Appointment.describe())`
`print('')`
`print(df.Date_Appointment.value_counts().describe())`
`print('')`
`print('Median = ', (round(df.Date_Appointment.value_counts().mean())))`
`print('Median = ', (round (df.Date_Appointment.value_counts().median())))`
`print('Mode = ', (df.Date_Appointment.value_counts().mode()))`
Would appreciate your detailed response. Thank you in advance.