Search code examples
pythoncorrelation

How do I calculate correlation in python Only the first 9 columns and the iloc function are to be used corr_matrix = dataset.iloc[:,0:8].corr()


What should go in the corr () argument? The idea is to used column parameters from 0 to 8 to find correlation

corr_matrix = dataset.iloc[:,0:8].corr()

The problem is using iloc with corr


Solution

  • Does the following work for you?:

    subset = dataset[["col1_name","col2_name", ..., "col8name"]] 
    corr_matrix = subset.corr()