Search code examples
pythonpandassklearn-pandas

Correlation Matrix in pandas showing only few columns


I have a dataframe with the following columns. enter image description here When I do correlation matrix, I see only the columns that are of int data types. I am new to ML, Can someone guide me what is the mistake I am doing here ?

enter image description here


Solution

  • As you correctly observe and @Kraigolas states from the docs

    numeric_onlybool, default True Include only float, int or boolean data.

    Meaning that by default will only compute values from numerical columns. You can change this by using:

    df.corr(numeric_only=False)
    

    However, this means pandas will try to converte the values to float to perform the correlation, but if the values in the columns are not numerical, it will fail returning:

    ValueError: could not convert string to float: 'X'