0

I was taking tutorial on pandas(dataframe) and came across an example (the code is given below)

import pandas as pd
df = pd.DataFrame([{'a':1,'c':2},{'a':3,'b':6,'c':8},{'a':78,'b':89,'c':78}])
print(df)

The output was:

    a     b   c
0   1   NaN   2
1   3   6.0   8
2  78  89.0  78

So only float is the datatype in the columns having NaN, while others have int as datatype by default. Can someone provide me with an explanation for this?

  • 2
    because NaN can't be treated as int. but it could be treated as float. that's why pandas converts b column to float and remaining other columns as it is – Mohamed Thasin ah Jun 01 '18 at 06:13
  • Whenever you have a missing value it is taken as "NaN". and type of NaN is float . Check type(np.nan) – Ram Jun 01 '18 at 06:21

0 Answers0