0
0
Pandasdata~20 mins

Scatter plots in Pandas - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Scatter Plot Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of a basic scatter plot code
What will be the output of this code snippet that creates a scatter plot using pandas and matplotlib?
Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'x': [1, 2, 3, 4], 'y': [10, 20, 25, 30]}
df = pd.DataFrame(data)
df.plot.scatter(x='x', y='y')
plt.show()
AA scatter plot with points at coordinates (1,10), (2,20), (3,25), (4,30) displayed
BA line plot connecting points (1,10), (2,20), (3,25), (4,30) displayed
CA bar chart with bars at x=1,2,3,4 with heights 10,20,25,30 displayed
DSyntaxError due to missing plt.scatter call
Attempts:
2 left
💡 Hint
Remember that df.plot.scatter creates a scatter plot, not a line or bar chart.
data_output
intermediate
1:30remaining
Number of points in scatter plot
Given this DataFrame and scatter plot code, how many points will appear in the scatter plot?
Pandas
import pandas as pd

data = {'height': [150, 160, 170, 180, 190], 'weight': [50, 60, 65, 80, 90]}
df = pd.DataFrame(data)
df.plot.scatter(x='height', y='weight')
A6
B4
C0
D5
Attempts:
2 left
💡 Hint
Each row in the DataFrame corresponds to one point in the scatter plot.
🔧 Debug
advanced
2:00remaining
Identify the error in scatter plot code
What error will this code raise when trying to create a scatter plot?
Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'a': [1, 2, 3], 'b': [4, 5, 6]}
df = pd.DataFrame(data)
df.plot.scatter(x='x', y='b')
plt.show()
ATypeError: unsupported operand type(s)
BValueError: x and y must be numeric
CKeyError: 'x'
DNo error, plot displays correctly
Attempts:
2 left
💡 Hint
Check if the DataFrame has a column named 'x'.
visualization
advanced
1:30remaining
Effect of color parameter in scatter plot
What will be the color of points in the scatter plot created by this code?
Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'x': [1, 2, 3], 'y': [4, 5, 6]}
df = pd.DataFrame(data)
df.plot.scatter(x='x', y='y', c='red')
plt.show()
APoints will have default blue color
BAll points will be red
CPoints will be green
DSyntaxError due to invalid color argument
Attempts:
2 left
💡 Hint
The color parameter sets the color of all points.
🚀 Application
expert
2:30remaining
Interpreting scatter plot with categorical color grouping
Given this DataFrame and scatter plot code, what does the color grouping represent in the plot?
Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'age': [25, 30, 22, 40, 35], 'income': [50000, 60000, 45000, 80000, 70000], 'gender': ['M', 'F', 'F', 'M', 'F']}
df = pd.DataFrame(data)
df.plot.scatter(x='age', y='income', c=df['gender'].map({'M': 'blue', 'F': 'pink'}))
plt.show()
ABlue points represent males, pink points represent females
BBlue points represent females, pink points represent males
CColors represent income levels, blue for high income, pink for low income
DColors represent age groups, blue for younger, pink for older
Attempts:
2 left
💡 Hint
Look at how the 'gender' column is mapped to colors.