NumPy or Pandas: Keeping array type as integer while having a NaN value

前端 未结 8 1091
粉色の甜心
粉色の甜心 2020-11-22 06:05

Is there a preferred way to keep the data type of a numpy array fixed as int (or int64 or whatever), while still having an element ins

8条回答
  •  無奈伤痛
    2020-11-22 06:31

    This is not a solution for all cases, but mine (genomic coordinates) I've resorted to using 0 as NaN

    a3['MapInfo'] = a3['MapInfo'].fillna(0).astype(int)
    

    This at least allows for the proper 'native' column type to be used, operations like subtraction, comparison etc work as expected

提交回复
热议问题