0
0
Data Analysis Pythondata~30 mins

Correlation with corr() in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Correlation with corr()
📖 Scenario: You are a data analyst working with a small dataset of students' scores in two subjects: Math and English. You want to find out if there is a relationship between their scores in these subjects.
🎯 Goal: Build a simple Python program that creates a dataset of students' scores, sets up a DataFrame, calculates the correlation between Math and English scores using corr(), and prints the result.
📋 What You'll Learn
Create a dictionary called scores with keys 'Math' and 'English' and the exact values: [88, 92, 79, 93, 85] and [84, 90, 78, 88, 82] respectively
Import pandas as pd
Create a DataFrame called df from the scores dictionary
Calculate the correlation between the 'Math' and 'English' columns using df['Math'].corr(df['English']) and store it in a variable called correlation
Print the correlation variable
💡 Why This Matters
🌍 Real World
Correlation helps to find relationships between variables, like how scores in one subject relate to another. This is useful in education, business, and science.
💼 Career
Data analysts and scientists use correlation to understand data patterns and make decisions based on relationships between variables.
Progress0 / 4 steps
1
Create the scores dictionary
Create a dictionary called scores with keys 'Math' and 'English'. Set the value for 'Math' to [88, 92, 79, 93, 85] and for 'English' to [84, 90, 78, 88, 82].
Data Analysis Python
Need a hint?

Use curly braces {} to create a dictionary. The keys are 'Math' and 'English'. The values are lists of numbers.

2
Import pandas and create DataFrame
Import the pandas library as pd. Then create a DataFrame called df from the scores dictionary using pd.DataFrame(scores).
Data Analysis Python
Need a hint?

Use import pandas as pd to import pandas. Then use pd.DataFrame() to create the DataFrame.

3
Calculate correlation between Math and English
Calculate the correlation between the 'Math' and 'English' columns in df using df['Math'].corr(df['English']). Store the result in a variable called correlation.
Data Analysis Python
Need a hint?

Use the corr() method on the 'Math' column and pass the 'English' column as argument.

4
Print the correlation result
Print the variable correlation to display the correlation value between Math and English scores.
Data Analysis Python
Need a hint?

Use print(correlation) to show the correlation value.