A column holds integers and NaN. Why does astype('int64') fail, and what is the usual fix?
Correct answer
C. int64 has no NaN representation, so the nullable Int64 dtype must be used instead
15 views
C. int64 has no NaN representation, so the nullable Int64 dtype must be used instead
15 views
Nullable integer dtypes such as Int64 keep a separate mask for missing values, which the fixed-width NumPy int64 cannot do, so astype('int64') raises when NaN is present. The alternatives are fillna with a sentinel, dropna, or converting to Int64 and letting downstream code handle pd.NA. Capitalisation matters: Int64 with a capital I is the extension type, int64 the NumPy one.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is C? Ask here and get an explanation.