I'd like to show the mean value in each boxplot. How can I add them?
I used the next code and I had this message:
TypeError: cannot convert the series to <class 'float'>
Thanks!
data_of=pd.read_csv(filename,header=0)
ax=plt.subplots(figsize=(20,8))
meanprops=dict(marker='D', markeredgecolor='black',markerfacecolor='black',markersize=10)
flierprops=dict(marker='.', markeredgecolor='black',markerfacecolor='white',markersize=10)
ax = sns.boxplot(x='MES', y='Finos', data=data_of, hue='ANO',linewidth=1,palette="Spectral_r",saturation=1,width=0.8,dodge=True
,showfliers=True,showmeans=True, meanprops=meanprops,flierprops=flierprops)
means = pd.DataFrame(data_of.groupby(['MES', 'ANO'])['Finos'].mean())
means.reset_index(inplace=True)
n = 0
for MES in means['MES'].unique():
valor = float(means.loc[(means.MES == MES) & (means.ANO == 'Yes')]['Finos'])
plt.text(n+0.1, valor, "{:.2f}".format(valor))
valor = float(means.loc[(means.MES == MES) & (means.ANO == 'No')]['Finos'])
plt.text(n-0.3, valor, "{:.2f}".format(valor))
n += 1