dataframe corr() 返回 empty dataframe

错误源于dataframe中的数据类型为object而非数字

df.dtypes可以查看数据类型

df.dtypes
Out[60]: 
IR_CELL_X_ID_CNT            object
IR_CELL_INLISTWITH_ID       object
IR_ID_X_CELL_NOTMAT_DAYS    object
IR_ID_INLISTWITH_CELL       object
dtype: object

此时用astype(float)转换为可以计算corr的类型

df2=df.astype(float)

In [62]: df2
Out[62]: 
       IR_CELL_X_ID_CNT  IR_CELL_INLISTWITH_ID  IR_ID_X_CELL_NOTMAT_DAYS  \
0                    1.0                    1.0                       NaN   
1                    1.0                    1.0                     193.0   
2                    1.0                    1.0                     222.0   
3                    1.0                    1.0                       NaN   
4                    NaN                    NaN                       NaN   


In [63]: df2.corr()
Out[63]: 
                          IR_CELL_X_ID_CNT  IR_CELL_INLISTWITH_ID  \
IR_CELL_X_ID_CNT                  1.000000               0.479672   
IR_CELL_INLISTWITH_ID             0.479672               1.000000   
IR_ID_X_CELL_NOTMAT_DAYS         -0.011823               0.010434   
IR_ID_INLISTWITH_CELL             0.479672               1.000000   

                          IR_ID_X_CELL_NOTMAT_DAYS  IR_ID_INLISTWITH_CELL  
IR_CELL_X_ID_CNT                         -0.011823               0.479672  
IR_CELL_INLISTWITH_ID                     0.010434               1.000000  
IR_ID_X_CELL_NOTMAT_DAYS                  1.000000               0.010434  
IR_ID_INLISTWITH_CELL                     0.010434               1.000000  

 

你可能感兴趣的:(dataframe corr() 返回 empty dataframe)