熊猫使用某些NaN将完整的数据框从float转换为int

时间:2020-11-03 11:53:50

标签: python pandas

我有一个数据框,其中包含带有浮点值和一些NaN的列 我正在尝试将nans替换为0并转换为int。

for col in df.columns:
if df[col].dtype == 'float64':
    df[col]=df.replace(np.nan(),0.0)
    df[col]= pd.to_numeric(df[col].astype(int),errors='coerce')

我收到一个错误的float对象不可调用

0 个答案:

没有答案