Let’s say we have a DataFrame that contains numbers in each column. For example, let’s say we have the following DataFrame:
DataFrame: 0 1 2 3 0 10 12 33 4 1 52 61 17 82 2 9 10 111 12
Now, we want to compute the pairwise correlation coefficients of columns of the DataFrame. In Python, we can compute the same using the DataFrame.corr() function.
import pandas df = pandas.DataFrame([[10, 12, 33, 4], [52, 61, 17, 82], [9, 10, 111, 12]]) print("DataFrame: \n", df) print("Correlation Coefficients: \n", df.corr())
The output of the above program will be:
DataFrame: 0 1 2 3 0 10 12 33 4 1 52 61 17 82 2 9 10 111 12 Correlation Coefficients: 0 1 2 3 0 1.000000 0.999898 -0.647059 0.993540 1 0.999898 1.000000 -0.657860 0.991822 2 -0.647059 -0.657860 1.000000 -0.556357 3 0.993540 0.991822 -0.556357 1.000000
Now, let’s have a closer look at the …






0 Comments