gpt4 book ai didi

python - 数据列值未更改为 float

转载 作者:行者123 更新时间:2023-11-28 22:24:02 26 4
gpt4 key购买 nike

我有一个数据框,

df,
Name Stage Description
0 sri 1 sri is one of the good singer in this two
1 nan 2 thanks for reading
2 ram 1 ram is two of the good cricket player
3 ganesh 1 one driver
4 nan 2 good buddies

tried df["Stage"]=pd.to_numeric(df["Stage"],downcast="float")

但值仍然相同

最佳答案

我想你需要astype :

df["Stage"]=df["Stage"].astype(float)

如果第一个解决方案因为某些非数字数据而失败,请使用 to_numeric使用参数 errors='coerce' 将错误数据替换为 NaNs,因此输出为 float :

df["Stage"]=pd.to_numeric(df["Stage"],errors="coerce")

关于python - 数据列值未更改为 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46709333/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com