I cannot understand why this value is Nan in the column "[lethalityRegionalSaude]"

Asked

Viewed 39 times

-1

#letalidade por estado
letalidadeRegionalSaude = []
for i in range(len(regional_saude)):
    letalidadeRegionalSaude.append(regional_saude.obitosNovos[i] * 100 / regional_saude.casosNovos[i])
print(letalidadeRegionalSaude)

[0.9345794392523364,
 4.123711340206185,
 3.4618410700236035,
 1.7267267267267268,
 4.545454545454546
...]

type(letalidadeRegionalSaude[1])
numpy.float64

#Adicionando uma coluna ao DataFrame
regional_saude['letalidadeRegionalSaude'] = pd.Series(letalidadeRegionalSaude)

regional_saude.head()

nomeRegiaoSaude       casosNovos     obitosNovos    populacaoTCU2019_int    letalidadeRegionalSaude
            
10ª REGIAO                 428             4              22328916.0                  NaN
  • letalidadeRegionalSaude is a series not a number, so the NaN.

  • I don’t understand!!! But it is not possible to insert a list as a column in a dataframe? Because my intention is this: convert a list with the "pd.Series()" method and put this series as a column in the dataframe.

  • Because that’s what I did with the column "populaTCU2019_int". This column was like "Object", I convert it to integer and insert it in the dataframe.

  • Convert the series to string that will achieve the desired result.

1 answer

-1

Theoretically what you did is right, another solution would be to do as follows:

for i in regional_saude.index:
    regional_saude['letalidadeRegionalSaude'] = letalidadeRegionalSaude[i]

Browser other questions tagged

You are not signed in. Login or sign up in order to post.