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

前端 未结 8 979
粉色の甜心
粉色の甜心 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条回答
  •  -上瘾入骨i
    2020-11-22 06:31

    NaN can't be stored in an integer array. This is a known limitation of pandas at the moment; I have been waiting for progress to be made with NA values in NumPy (similar to NAs in R), but it will be at least 6 months to a year before NumPy gets these features, it seems:

    http://pandas.pydata.org/pandas-docs/stable/gotchas.html#support-for-integer-na

    (This feature has been added beginning with version 0.24 of pandas, but note it requires the use of extension dtype Int64 (capitalized), rather than the default dtype int64 (lower case): https://pandas.pydata.org/pandas-docs/version/0.24/whatsnew/v0.24.0.html#optional-integer-na-support )

提交回复
热议问题