C. The DataFrame has non-numeric columns which corr() cannot process
D. The DataFrame columns have missing values
Solution
Step 1: Analyze DataFrame columns
Column 'Y' contains strings, which are non-numeric.
Step 2: Understand corr() requirements
corr() only works on numeric columns; non-numeric columns cause it to ignore or error depending on pandas version.
Final Answer:
The DataFrame has non-numeric columns which corr() cannot process -> Option C
Quick Check:
corr() needs numeric data [OK]
Hint: Check for non-numeric columns before using corr() [OK]
Common Mistakes:
Assuming corr() works on strings
Thinking misspelling caused error
Ignoring data types in DataFrame
5. You have a DataFrame df with columns height, weight, and age. You want to find which two variables have the strongest positive correlation. Which code snippet correctly finds this?
hard
A. corr_matrix = df.corr()
max_corr = corr_matrix.where(corr_matrix < 1).max().max()
B. corr_matrix = df.corr()
max_corr = corr_matrix.where(corr_matrix != 1).min().min()
C. corr_matrix = df.corr()
max_corr = corr_matrix.max().max()
D. corr_matrix = df.corr()
max_corr = corr_matrix.where(corr_matrix != 1).max().max()
Solution
Step 1: Calculate correlation matrix
Use df.corr() to get correlations between all numeric columns.
Step 2: Exclude self-correlation (which is 1)
Use where(corr_matrix != 1) to ignore diagonal 1s, then find the maximum correlation value.
Step 3: Find the strongest positive correlation
Use max().max() to get the highest correlation excluding 1.