Find all columns of dataframe in Pandas whose type is float, or a particular type?

前端 未结 3 1134
暖寄归人
暖寄归人 2020-12-13 02:08

I have a dataframe, df, that has some columns of type float64, while the others are of object. Due to the mixed nature, I cannot use

df.fillna(\'unknown\')          


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-13 02:25

    This is conciser:

    # select the float columns
    df_num = df.select_dtypes(include=[np.float])
    # select non-numeric columns
    df_num = df.select_dtypes(exclude=[np.number])
    

提交回复
热议问题