【发布时间】:2020-11-06 11:55:45
【问题描述】:
我需要将我的列 Votes 从一个对象更改为一个浮点数,但每次我使用 to_numeric 它都会返回 NaN。
dados["Votes"] = pd.to_numeric(dados["Votes"],errors="coerce")
dados["Votes"]
0 NaN
1 NaN
2 NaN
3 NaN
4 NaN
..
995 NaN
996 NaN
997 NaN
998 NaN
999 NaN
Name: Votes, Length: 1000, dtype: float64
【问题讨论】:
-
你能分享一个你输入数据的样本吗?
-
请分享您的
dados['Votes']样本。原因可能是Votes列中有许多str类型值以及float值。 -
可能你有不能转换为浮动的对象。您可以将那些替换为零,例如 dados["Votes"] = pd.to_numeric(dados["Votes"],errors="coerce").fillna(0, downcast='infer')
-
0 2,295,987 1 1,584,782 2 2,260,649 3 1,107,253 4 1,614,369 ... 995 256 256,515 996 367,489 997 1397 1397 139,634 9998 42,160 topt
标签: python pandas dataframe series