In [12]:
# convert objects will handle multiple whitespace, this will convert them to NaN
# we then call fillna to convert those to 0
df.Age = df[['Age']].convert_objects(convert_numeric=True).fillna(0)
df
Out[12]:
Name Age
0 John 12
1 Mary 0
2 Tim 15
使用内置方法^{} 并设置参数
convert_numeric=True
:这是从this, more thorough question修改的答案。我会让它更像Python,解决你的问题。
其中
d
是您的数据帧。相关问题 更多 >
编程相关推荐