【发布时间】:2018-11-14 21:59:04
【问题描述】:
我想将具有值 -1.0、0.0 和 Nans 的列转换为 int。 pd.tonumeric 和 myCol.astype 我都试过了
myCol = pd.to_numeric(myCol,downcast='signed', errors = 'coerce')
myCol.astype(np.int64, errors= 'ignore')
这些方法都不起作用。 所需的输入和输出
input: myCol = pd.Series([np.nan, 0.0, -1.0, 0.0, 0.0, 2.0])
output: Nan, 0, -1, 0, 0, 2
谢谢。
【问题讨论】:
-
你期望
NaN的int值是多少? -
输入是什么,输出是什么,期望的输出是什么?样本可以帮助我们诊断问题
-
@G.Anderson 对不起。刚刚编辑。
-
你当前的输出是什么?
-
pandas 的一个不幸特性是任何带有 NaN 的数值列都会自动变成浮点数据类型。您可以转换为字符串并修剪。但是,该列将是数据类型“对象”。