Error while multplying decimal numbers in pyhton

65 Views Asked by At

I am working on a project for a job opportunity and it was asked to handle disease facts. I was running the code and the calculations worked just fine in Python and at some point, the results started t get an error "NAN" values.

I will display the code I've made :

  • The code before the error :
# Calculation of the weight of the population by age

#Uganda
# Sum of observations from the column "Estimates, Uganda, 2019"
total_observation = transposed_df["Estimates, Uganda, 2019"].sum()

# The weight in percentage for each observation
transposed_df["Weight Percentage Uganda"] = (transposed_df["Estimates, Uganda, 2019"] / total_observation)

##### 
#United States of America

# Sum of observations from the column "Estimates, Uganda, 2019"
total_observation1 = transposed_df["Estimates, United States of America, 2019"].sum()

# The weight in percentage for each observation
transposed_df["Weight Percentage United States of America"] = (transposed_df["Estimates, United States of America, 2019"] / total_observation1)

#print
transposed_df

at this point, no Nan values on the outcome. I have checked out.

  • The code where the error occurs:
#Age-standardized rate from Uganda 

transposed_df["Age-standardized rate from Uganda"] = (COPD["Death rate, Uganda, 2019"] * transposed_df["Weight Percentage Uganda"])

#Age-standardized rate from United States of America

transposed_df["Age-standardized rate from United States of America"] = (COPD["Death rate, United States, 2019"] * transposed_df["Weight Percentage United States of America"])

#display result
transposed_df

It's a simple equation and the latest numbers started to break I don't know why. I also checked and at this point in the project, they became null values. I displayed the image where the error occurred. CHECK THE IMAGE OF THE TABLE HERE

Above, is the table named COPD:

Age group (years) Death rate, United States, 2019 Death rate, Uganda, 2019
0-4 0.04 0.40
5-9 0.02 0.17
10-14 0.02 0.07
15-19 0.02 0.23
20-24 0.06 0.38
25-29 0.11 0.40
30-34 0.29 0.75
35-39 0.56 1.11
40-44 1.42 2.04
45-49 4.00 5.51
50-54 14.13 13.26
55-59 37.22 33.25
60-64 66.48 69.62
65-69 108.66 120.78
70-74 213.10 229.88
75-79 333.06 341.06
80-84 491.10 529.31
85+ 894.45 710.40
  • I tried to find null values but they started to appear once I made the calculation and it's only on the latest results.
  • Is not a division by zero, they are decimal values.
  • Outcomes not provided, only in some rows.
0

There are 0 best solutions below