2020-07-20
阅读量:
3004
Python如何将Series type:object转换为int
1)使用pd.to_numeric进行转换,而解析字符串“ None”时出错2)然后我尝试将NaN替换为None值:替换问题
1.1)
pd.to_numeric(df ['Var1'],downcast ='integer')ValueError:无法在位置44816处解析字符串“ None”
1.2)
df.astype({'Var1':'int64'})。dtypes TypeError:int()参数必须是字符串,类似字节的对象或数字,而不是'NoneType'
2)
df ['Var1']。astype(str).astype(int)ValueError:int()以10为底的无效文字:“无”
实际结果:dtype:无效预期结果:dtype:int64






评论(0)


暂无数据
推荐帖子
0条评论
0条评论
0条评论