Based on the data in the Table , an ordered schedule of boxes with a mustache was constructed. However, when adding the function of the average (line 11), the graph shifts, why?
import pandas as pd import matplotlib.pyplot as plt df = pd.read_excel(r'C:\Users\cinem\Desktop\нир\3-6.xlsx') r = df.pivot_table(columns='town_name', index='cld_year', values='относительная заболеваемость на 1000 чел.', aggfunc='mean', fill_value=0) aq = r.median().sort_values().index ae = r.mean().sort_values().index r[aq].plot.box(rot=90, figsize=(16,10)) r[ae].mean().plot(kind='line', color='orange', rot=90) plt.ylabel('Относительная заболеваемость на 1000 чел.') plt.xlabel('город') plt.title('Относительная заболеваемость на 1000 человек в городах РФ') plt.tight_layout() plt.show() 

