Movatterモバイル変換


[0]ホーム

URL:


Menu
×
See More 
Sign In
+1 Get Certified Upgrade For Teachers Spaces Get Certified Upgrade For Teachers Spaces
   ❮     
     ❯   

Pandas -Data Correlations


Finding Relationships

A great aspect of the Pandas module is thecorr() method.

Thecorr() method calculates the relationship between each column in your data set.

The examples in this page uses a CSV file called: 'data.csv'.

Download data.csv. orOpen data.csv

Example

Show the relationship between the columns:

df.corr()
Try it Yourself »

Result

            Duration     Pulse  Maxpulse  Calories  Duration  1.000000 -0.155408  0.009403  0.922721  Pulse    -0.155408  1.000000  0.786535  0.025120  Maxpulse  0.009403  0.786535  1.000000  0.203814  Calories  0.922721  0.025120  0.203814  1.000000

Note: Thecorr() method ignores "not numeric" columns.

Result Explained

The Result of thecorr() method is a table with a lot of numbers that representshow well the relationship is between two columns.

The number varies from -1 to 1.

1 means that there is a 1 to 1 relationship (a perfect correlation),and for this data set, each time a value went up in the first column, the other one went up as well.

0.9 is also a good relationship, and if you increase one value, the other will probably increase as well.

-0.9 would be just as good relationship as 0.9, but if you increase one value, the other will probably go down.

0.2 means NOT a good relationship, meaning that if one value goes up does not mean that the other will.

What is a good correlation? It depends on the use, but I think it is safe to say you have to have at least0.6 (or-0.6) to call it a good correlation.

Perfect Correlation:

We can see that "Duration" and "Duration" got the number1.000000, which makes sense,each column always has a perfect relationship with itself.

Good Correlation:

"Duration" and "Calories" got a0.922721 correlation, which is a very good correlation, and we can predict that the longer you work out, the more calories you burn, and the other way around: if you burned a lot of calories, you probably had a long work out.

Bad Correlation:

"Duration" and "Maxpulse" got a0.009403 correlation, which is a very bad correlation, meaning that we can not predict the max pulse by just looking at the duration of the work out, and vice versa.




×

Contact Sales

If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail:
sales@w3schools.com

Report Error

If you want to report an error, or if you want to make a suggestion, send us an e-mail:
help@w3schools.com

W3Schools is optimized for learning and training. Examples might be simplified to improve reading and learning.
Tutorials, references, and examples are constantly reviewed to avoid errors, but we cannot warrant full correctness
of all content. While using W3Schools, you agree to have read and accepted ourterms of use,cookies andprivacy policy.

Copyright 1999-2025 by Refsnes Data. All Rights Reserved.W3Schools is Powered by W3.CSS.


[8]ページ先頭

©2009-2025 Movatter.jp