0
0
Data Analysis Pythondata~30 mins

Scatter plots with regression (regplot) in Data Analysis Python - Mini Project: Build & Apply

Choose your learning style9 modes available
Scatter plots with regression (regplot)
📖 Scenario: You are a data analyst working with a small dataset of students' study hours and their exam scores. You want to visualize the relationship between study hours and exam scores using a scatter plot. Additionally, you want to add a regression line to see the trend clearly.
🎯 Goal: Create a scatter plot with a regression line using the seaborn library to visualize the relationship between study hours and exam scores.
📋 What You'll Learn
Create a dictionary called data with keys 'Hours' and 'Scores' and the exact values specified.
Create a pandas DataFrame called df from the data dictionary.
Create a variable called plot_color and set it to the string 'blue'.
Use seaborn.regplot with df['Hours'] as x, df['Scores'] as y, and color=plot_color to create the scatter plot with regression line.
Use plt.show() to display the plot.
💡 Why This Matters
🌍 Real World
Scatter plots with regression lines help analysts understand relationships between two variables, such as study hours and exam scores, to make data-driven decisions.
💼 Career
Data analysts and scientists often use scatter plots with regression lines to visualize trends and correlations in data, which is essential for reporting and predictive modeling.
Progress0 / 4 steps
1
Create the data dictionary and DataFrame
Create a dictionary called data with keys 'Hours' and 'Scores'. Set 'Hours' to the list [1, 2, 3, 4, 5, 6, 7, 8] and 'Scores' to the list [35, 40, 50, 55, 65, 70, 75, 80]. Then create a pandas DataFrame called df from the data dictionary.
Data Analysis Python
Hint

Use data = {'Hours': [...], 'Scores': [...]} and then df = pd.DataFrame(data).

2
Set the plot color
Create a variable called plot_color and set it to the string 'blue'.
Data Analysis Python
Hint

Just write plot_color = 'blue'.

3
Create the scatter plot with regression line
Import seaborn as sns and matplotlib.pyplot as plt. Use sns.regplot with df['Hours'] as x, df['Scores'] as y, and color=plot_color to create the scatter plot with regression line.
Data Analysis Python
Hint

Use sns.regplot(x=df['Hours'], y=df['Scores'], color=plot_color).

4
Display the plot
Use plt.show() to display the scatter plot with regression line.
Data Analysis Python
Hint

Use plt.show() to display the plot window.