Skip to learning content

DATA SCIENCE PYTHON PLAYGROUND

Data Foundations · A little practice goes a long way.

← Inspect lessonsTINY TABLES · REAL PYTHON · YOUR PACE
Reading the whole table · I21 · 8 MIN

Inspect numeric relationships

Read correlation as association, not causation.

Exercises within this concept

  1. FollowFollow the techniqueCurrent exercise
  2. ChangeAdapt a requirement
  3. TransferCombine earlier skills

Understand the idea

Correlation summarizes how two numeric measurements move together along a straight-line pattern.

Concept sketch: correlation: symmetric, from −1 to 1xyzx1.00.5-0.5y0.51.00.0z-0.50.01.0correlation: symmetric, from −1 to 1
Illustration · not the exercise output

A small example

If x increases as y increases, correlation is positive. If y decreases instead, it is negative.

Follow the code

Apply the idea to the supplied table. Read from top to bottom; the final line displays the result.

df.corr(numeric_only=True)

What each part does

df.corr(numeric_only=True)
correlations among numeric columns
numeric_only=True
leave text columns out
diagonal
a varying column correlates 1 with itself

Your inputs

The editable setup on the right creates df. Run executes the setup and your work from top to bottom.

Study club · 8 synthetic rows
studentclubhoursscoregroup
AriArt152A
BoCode371A
CyArt265B
DeeCode482B
EliArt589A
FloCode376A
GusArt693B
HanCode261B

Your task · Follow

Using df, return the correlation matrix for all numeric columns in Study club.

Hint

Select numeric measurements and remember that a matrix reports pairwise linear associations.

Reveal solution

One way to do it. Keep any supplied setup in the editor and use this in the Your work section.

df.corr(numeric_only=True)
Your task · Follow

Using df, return the correlation matrix for all numeric columns in Study club.

Tab: indent · Shift+Tab: outdent · Esc, then Tab: leave editor

Edit Python. Control or Command plus Enter runs it. Tab indents by four spaces. Shift plus Tab outdents. Press Escape, then Tab or Shift plus Tab to leave the editor.

Each run executes all editor code in a fresh Python session. Display a value by leaving it on the final line.

Python starts when you open a lesson.

Output

Run your code to see what Python returns.