Pandas divide返回NaN

jbose2ul  于 2023-03-28  发布在  其他
关注(0)|答案(1)|浏览(130)

我试图划分两列,但它们返回NaN。

column1的输出

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

column2的输出

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

除法输出

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

print(ans)
104      NaN
124391   NaN
dtype: float64

我只想知道爱尔兰接种疫苗人数的百分比。
我也试过把爱尔兰_population转换成像下面这样的浮点数,但是没有用。
ireland_population['population'] = ireland_population['population'].astype('float64')

7vux5j2d

7vux5j2d1#

在我看来,你上面的代码检索的索引值。尝试使用下一个代码:

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

相关问题