Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
2
Indexable
Never
df_patient_info_filtered['age_new'] = df_patient_info_filtered['age'].apply(lambda x: int(x.split('s')[0]))  # pasidarom int kuri rikiuos normaliai.
data_frame=df_patient_info_filtered
group_by='age_new'  # grupuojam pagal nauja stulpeli.
avg_parameter='confirmed_to_released'
x_label='Age group'
y_label='Time period in days '
title='Distribution of avarage time period from confirmation of virus infection to release'


group_avg = data_frame.groupby(group_by)[avg_parameter].mean().reset_index()
num_bars = len(group_avg)
fig = plt.figure(figsize=(12, 4) if num_bars >= 5 else (5, 4))

ax = sns.barplot(x=group_by, y=avg_parameter, data=group_avg)
ax.spines[['top', 'right']].set_visible(False)

for index, row in group_avg.iterrows():
    value = row[avg_parameter]
    if np.isfinite(value) and not np.isnan(value):
        if value or value > 0:
            plt.bar(row.name, value, edgecolor='black', color='lightgrey')
            ax.text(row.name, value, f'{value:.2f}', ha='center', va='bottom')
            
labels = [tick.get_text() + 's' for tick in ax.get_xticklabels()]  # redaguojam labelius pridedami s.
ax.set_xticklabels(labels)  # uzdedam naujus labelius.

plt.show()