0
0
Matplotlibdata~10 mins

Correlation matrix visualization in Matplotlib - Interactive Code Practice

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

Complete the code to import the matplotlib library for plotting.

Matplotlib
import [1] as plt
Drag options to blanks, or click blank then click option'
Amatplotlib.pyplot
Bseaborn
Cpandas
Dnumpy
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the whole matplotlib instead of pyplot.
Using seaborn or pandas instead of matplotlib.pyplot.
2fill in blank
medium

Complete the code to calculate the correlation matrix from the DataFrame 'df'.

Matplotlib
corr_matrix = df.[1]()
Drag options to blanks, or click blank then click option'
Acorr
Bcov
Cmean
Dsum
Attempts:
3 left
💡 Hint
Common Mistakes
Using cov() which calculates covariance, not correlation.
Using aggregation functions like mean() or sum().
3fill in blank
hard

Fix the error in the code to display the correlation matrix as a heatmap using matplotlib.

Matplotlib
plt.imshow(corr_matrix, cmap=[1])
plt.colorbar()
plt.show()
Drag options to blanks, or click blank then click option'
Acoolwarm
B'coolwarm'
C'heatmap'
Dheatmap
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the colormap name without quotes causing a NameError.
Using an invalid colormap name like 'heatmap'.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each word to its length only if the length is greater than 3.

Matplotlib
lengths = {word: [1] for word in words if [2]
Drag options to blanks, or click blank then click option'
Alen(word)
Bword
Clen(word) > 3
Dword > 3
Attempts:
3 left
💡 Hint
Common Mistakes
Using the word itself instead of its length as the value.
Comparing the word string directly to a number.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps uppercase keys to values only if the value is positive.

Matplotlib
result = { [1]: [2] for k, v in data.items() if [3] > 0 }
Drag options to blanks, or click blank then click option'
Ak.upper()
Bv
Dk
Attempts:
3 left
💡 Hint
Common Mistakes
Using the original key without uppercase conversion.
Using the wrong variable names for keys or values.