Preparation
Before any data manipulation can occur, two (2) new libraries will require installation.
- The Pandas library enables access to/from a DataFrame.
- The NumPy library supports multi-dimensional arrays and matrices in addition to a collection of mathematical functions.
To install these libraries, navigate to an IDE terminal. At the command prompt ($
), execute the code below. For the terminal used in this example, the command prompt is a dollar sign ($
). Your terminal prompt may be different.
$ pip install pandas
Hit the <Enter>
key on the keyboard to start the installation process.
$ pip install numpy
Hit the <Enter>
key on the keyboard to start the installation process.
If the installations were successful, a message displays in the terminal indicating the same.
Feel free to view the PyCharm installation guide for the required libraries.
Add the following code to the top of each code snippet. This snippet will allow the code in this article to run error-free.
import pandas as pd import numpy as np
DataFrame corr()
The corr()
method computes pair-wise correlation of columns. This does not include NaN
and NULL values.
The syntax for this method is as follows:
DataFrame.corr(method='pearson', min_periods=1)
Parameter | Description |
---|---|
method | The possible correlation methods are: – 'pearson' : standard correlation coefficient. By default, Pearson.– 'kendall' : Kendall Tau correlation coefficient.– 'spearman' : Spearman rank correlation.– Callable with two (2) 1D ndarrays and returns a float. |
min_periods | The minimum number of observations required per pair of columns to have a valid result. This option is only available for the Pearson and Spearman correlations. |
df_prices = pd.DataFrame({'Tops': [10.22, 12.45, 17.45], 'Tanks': [9.99, 10.99, 11.99], 'Pants': [24.95, 26.95, 32.95], 'Sweats': [18.99, 19.99, 21.99]}) result = df_prices.corr() print(result)
- Line [1] creates a DataFrame from a Dictionary of Lists and saves it to
df_inv
. - Line [2] applies the correlation method. The output saves to the
result
variable. - Line [3] outputs the result to the terminal.
Output
Tops | Tanks | Pants | Sweats | |
Tops | 1.000000 | 0.976398 | 0.997995 | 0.999620 |
Tanks | 0.976398 | 1.000000 | 0.960769 | 0.981981 |
Pants | 0.997995 | 0.960769 | 1.000000 | 0.995871 |
Sweats | 0.999620 | 0.981981 | 0.995871 | 1.000000 |
More Pandas DataFrame Methods
Feel free to learn more about the previous and next pandas DataFrame methods (alphabetically) here:
Also, check out the full cheat sheet overview of all Pandas DataFrame methods.

At university, I found my love of writing and coding. Both of which I was able to use in my career.
During the past 15 years, I have held a number of positions such as:
In-house Corporate Technical Writer for various software programs such as Navision and Microsoft CRM
Corporate Trainer (staff of 30+)
Programming Instructor
Implementation Specialist for Navision and Microsoft CRM
Senior PHP Coder