0
0
Pandasdata~10 mins

Scatter plots in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a scatter plot using pandas.

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=[1])
plt.show()
Drag options to blanks, or click blank then click option'
Ax
Bindex
Cy
Dz
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'x' for both axes causes a line, not a scatter plot.
Using a non-existent column like 'z' causes an error.
2fill in blank
medium

Complete the code to set the color of points in the scatter plot.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'height': [150, 160, 170, 180], 'weight': [50, 60, 65, 70]}
df = pd.DataFrame(data)
df.plot.scatter(x='height', y='weight', c=[1])
plt.show()
Drag options to blanks, or click blank then click option'
A'blue'
B'circle'
C'scatter'
D'line'
Attempts:
3 left
💡 Hint
Common Mistakes
Using shape names like 'circle' instead of color names.
Passing plot types like 'scatter' or 'line' as color.
3fill in blank
hard

Fix the error in the code to correctly plot a scatter plot with size variation.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'age': [20, 25, 30, 35], 'income': [2000, 2500, 3000, 3500], 'score': [10, 20, 30, 40]}
df = pd.DataFrame(data)
df.plot.scatter(x='age', y='income', s=[1])
plt.show()
Drag options to blanks, or click blank then click option'
Adf['score']
B'score'
Cscore
Ddf.score()
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the column name as a string instead of the Series.
Trying to call the column as a method.
4fill in blank
hard

Fill both blanks to create a scatter plot with custom marker and transparency.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'temp': [30, 35, 40, 45], 'sales': [100, 150, 200, 250]}
df = pd.DataFrame(data)
df.plot.scatter(x='temp', y='sales', marker=[1], alpha=[2])
plt.show()
Drag options to blanks, or click blank then click option'
A'x'
B0.5
C1.5
D'o'
Attempts:
3 left
💡 Hint
Common Mistakes
Using alpha values greater than 1 causes errors.
Using invalid marker strings.
5fill in blank
hard

Fill all three blanks to create a scatter plot with color, size, and title.

Pandas
import pandas as pd
import matplotlib.pyplot as plt

data = {'speed': [5, 10, 15, 20], 'distance': [50, 100, 150, 200], 'weight': [100, 200, 300, 400]}
df = pd.DataFrame(data)
ax = df.plot.scatter(x=[1], y=[2], s=[3], c='red')
ax.set_title('Speed vs Distance')
plt.show()
Drag options to blanks, or click blank then click option'
A'speed'
B'distance'
Cdf['weight']
D'weight'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing column names as strings for size instead of Series.
Mixing up x and y axis names.