Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas divide returns NaN

I am trying to divide two columns but they return NaN.
Output of column1

print(ireland_population['population'])
104    5023108
Name: population, dtype: int64

Output of column2

print(ireland['people_fully_vaccinated'])
124391    4061525.0
Name: people_fully_vaccinated, dtype: float64

Output of division

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

ans = ireland['people_fully_vaccinated'] /  ireland_population['population']

print(ans)
104      NaN
124391   NaN
dtype: float64

I just want the one number for the percentage of people who were fully vaccinated in Ireland.
I have also tried converting ireland_population to a float like below but that didn’t help.
ireland_population['population'] = ireland_population['population'].astype('float64')

>Solution :

It seems to me that your code above retrieves the indices with the values.
Try to use the next code:

ans = ireland['people_fully_vaccinated'].values / ireland_population['population'].values
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading