1
import numpy as np
import pandas as pd
ID = [i for i in range(1,101)]
def tabela(imc):
if imc < 18.5:
return 'Abaixo do peso'
elif imc < 25 and imc >= 18.5:
return 'Saudável'
elif imc < 30 and imc >= 25:
return 'Acima do peso'
elif imc < 35 and imc >= 30:
return 'Obesidade grau I'
elif imc < 40 and imc >= 35:
return 'Obesidade grau II'
else:
return 'Obesidade grau III'
pd.options.display.max_rows = 999
altura, peso=np.loadtxt('data.csv',delimiter=':',dtype='float',unpack=True)
imc = peso/altura**2
classificacao = []
for i in imc:
classificacao.append(tabela(i))
data = {'Altura' : altura,
'Peso' : peso,
'IMC' : imc,
'Classificação': classificacao,
'Chamada':chamada}
df = pd.DataFrame(data,columns = ['Altura','Peso','IMC','Classificação'],index=data['ID'])
decimal = pd.Series([2,2,1],index=['Altura','Peso','IMC'])
df.sort_values(by='IMC')
print(df.round(decimal))
table/output:
- Height | Weight | IMC | Classification
- 1 1.88 | 91.45 | 25.8 | Overweight
- 2 1.82 | 95.65 | 29.0 | Overweight
- 3 1.88 | 94.01 | 26.5 | Overweight
- 4 1.74 | 63.55 | 21.0 | Healthy
- 5 1.69 | 66.12 | 23.1 | Healthy
- 6 1.75 | 68.84 | 22.5 | Healthy
- 7 1.75 | 82.72 | 26.9 | Overweight
.....
The values are only formatted this way due to pd.round(decimal), however, I would like to use another formatting next to the one that would be pd.sort_values(by='IMC'). I can’t use both at the same time and then print already reformatted.