将Nan转换为0

时间:2020-09-03 12:45:37

标签: python arrays numpy

这是我的代码:

prices = np.array(df[['1r_start', '1r_end', '2r_start', '2r_end', '3r_start', '3r_end', '4r_start', '4r_end', '5r_start', '5r_end', '6r_start',

'6r_end','studio_start','studio_end']])

它的类型= np.ndarray

然后,如果我尝试这段代码:

prices = np.nan_to_num(0)

价格类型变为np.int64

数组的形状为(1121,14)

1 个答案:

答案 0 :(得分:1)

尝试:

prices = df.to_numpy(dtype=int)

这会将您的数据帧转换为numpy数组,并通过将类型指定为int,它将用int的Null值0填充na值。请参见the documentation更多信息。