Pandas divide returns NaN

Question:

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

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')

Asked By: MichaelLong102

||

Answers:

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
Answered By: Strikoder
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.