I'm trying to save the values from populatioEst column in float variables using Python3 & Pandas, I have the following table:
Name | populationEst |
---|---|
Amsterdam | 872757 |
Netherlands | 17407585 |
I'm trying to save the values from populatioEst column in float variables using Python3 & Pandas, I have the following table:
Name | populationEst |
---|---|
Amsterdam | 872757 |
Netherlands | 17407585 |
Is this what are you looking for?
populationAM = pops.loc[pops.Name == 'Amsterdam', 'populationEst'].iloc[0]
populationNL = pops.loc[pops.Name == 'Netherlands', 'populationEst'].iloc[0]
frac = populationAM * 100 / populationNL
The value of frac
here is 5.013659275539944, while populationAM
and populationNL
are the integers corresponding to the respective populations (as you can see, the type of these variables is not a problem to compute the correct value of frac
). In your code, the issue is that populationAM
and populationNL
are pandas Series, instead of integers; iloc[0]
retrieves the value in the first position of the series.