CBSE Class 12 Informatics Practices Question 84 of 101

Python Pandas — II — Question 8

Back to all questions
8
Question

Question 8

Why does Python change the datatype of a column as soon as it stores an empty value (NaN) even though it has all other values stored as integer ?

Answer

When a column in a pandas DataFrame contains a mixture of integers and missing values (NaNs), the data type is automatically changed to a floating-point type to accommodate these missing values because in Python integer types cannot store NaN values.