Last active
September 5, 2018 18:28
-
-
Save fcunhaneto/94ed2b2af552a7946db2ac888ecfb066 to your computer and use it in GitHub Desktop.
Criando um boxplot para a coluna alturas, e para as alturas femininas e masculinas
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import matplotlib.pyplot as plt | |
""" | |
Criando um boxplot para a coluna alturas, e para as alturas femininas e | |
masculinas | |
""" | |
df = pd.read_csv('questionario.csv') | |
alt = df['Alt'] | |
alt_f = df[df.Sexo == 'F'] | |
alt_f = alt_f['Alt'] | |
alt_m = df[df.Sexo == 'M'] | |
alt_m = alt_m['Alt'] | |
alt_d = alt.describe() | |
alt_fd = alt_f.describe() | |
alt_md = alt_m.describe() | |
s_describe = {'G': alt_d, 'F': alt_fd, 'M': alt_md} | |
for x in s_describe: | |
f_name = 'altura-descricao-{0}.txt'.format(x) | |
with open(f_name, 'w') as f: | |
alt_descri.to_string(f) | |
font_1 = {'family':'serif', 'color':'#993556'} | |
font_2 = {'family':'serif', 'color':'#5C1BCC'} | |
font_3 = {'family':'serif', 'color':'000', 'size':12} | |
fig = plt.figure(figsize=(6, 8)) | |
plt.boxplot([alt, alt_f, alt_m], labels=['Geral', 'Fem', 'Masc']) | |
plt.ylabel('Idade') | |
i = 1 | |
for ax in s_describe: | |
plt.text(i, s_describe[ax]['50%'], '{0:.2f}'.format(s_describe[ax]['50%']), | |
fontdict=font_2) | |
plt.text(i, s_describe[ax]['25%'], '{0:.2f}'.format(s_describe[ax]['25%']), | |
fontdict=font_1) | |
plt.text(i, s_describe[ax]['75%'], '{0:.2f}'.format(s_describe[ax]['75%']), | |
fontdict=font_1) | |
i += 1 | |
plt.xticks([1, 2, 3], ['G', 'F', 'M']) | |
plt.text(2.8, 1.45, 'G - Geral\nF - Feminino\nM - Masculino', | |
horizontalalignment='left', fontdict=font_3) | |
plt.savefig('alturas-geral-fem-masc-boxplot.png') | |
plt.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment