df['Value'] = [-2,254.00, 3,452.00, 15,698.00, -6,258.00]
数据类型是saying object。我想把它们转换成整数,但我得到了一个错误
使用df.astype
:
In [2329]: df['Value'] = df['Value'].astype(int)
In [2329]: df['Value']
Out[2329]:
0 -2
1 254
2 3
3 452
4 15
5 698
6 -6
7 258
Name: Value, dtype: int64
您可以尝试以下代码:
df['Value'] = df['Value'].astype(dtype='int64')
将pd.to_numeric
与errors='coerce'
一起使用
df['Value'] = pd.to_numeric(df['Value'], errors='coerce')