C. DataFrame with bmi column calculated as weight_kg multiplied by height_cm
D. DataFrame with bmi column calculated as weight_kg divided by height_cm squared in meters
Solution
Step 1: Understand the BMI calculation in code
BMI is weight in kg divided by height in meters squared. The code correctly converts height_cm to meters and squares it.
Step 2: Check output format
The print shows a DataFrame with a new 'bmi' column calculated as described, not a dictionary or error.
Final Answer:
DataFrame with bmi column calculated as weight_kg divided by height_cm squared in meters -> Option D
Quick Check:
BMI = weight / (height/100)^2 [OK]
Hint: Check formula carefully for correct calculation [OK]
Common Mistakes:
Confusing multiplication with division in BMI formula
Expecting dictionary output instead of DataFrame
Thinking code causes syntax error
4. The following code tries to create a new feature income_level but raises an error. What is the error and how to fix it?
df['income_level'] = df['income'].apply(lambda x: 'high' if x > 50000 else 'low' if x <= 50000)
medium
A. No error; code runs fine
B. SyntaxError due to missing else clause; fix by adding final else
C. KeyError because 'income' column does not exist
D. TypeError because apply cannot use lambda functions
Solution
Step 1: Identify the lambda function structure
The lambda uses nested if-else but misses a final else clause, causing SyntaxError.
Step 2: Fix the lambda expression
Add a final else clause to cover all cases, e.g., lambda x: 'high' if x > 50000 else 'low'.
Final Answer:
SyntaxError due to missing else clause; fix by adding final else -> Option B
Quick Check:
Lambda if-else must cover all cases [OK]
Hint: Ensure lambda if-else has final else clause [OK]
Common Mistakes:
Assuming apply cannot use lambda
Ignoring missing else causing syntax error
Thinking income column is missing without checking
5. You have a dataset with columns temperature_c and humidity. You want to create a new feature heat_index that combines both to better predict discomfort. Which approach best explains why engineered features like heat_index improve analysis?
hard
A. Combining temperature and humidity into heat_index captures interaction effects raw features miss
B. Using only temperature or humidity separately is always better for simplicity
C. Heat_index replaces raw data so original features are no longer needed
D. Engineered features like heat_index reduce dataset size by removing columns
Solution
Step 1: Understand interaction effects in features
Heat index combines temperature and humidity to capture how they jointly affect discomfort, which single features miss.
Step 2: Evaluate other options
Options A, C, and D misunderstand feature engineering benefits or effects on data.
Final Answer:
Combining temperature and humidity into heat_index captures interaction effects raw features miss -> Option A
Quick Check:
Engineered features = capture interactions [OK]
Hint: Engineered features capture combined effects of raw data [OK]
Common Mistakes:
Thinking single features are always better
Believing engineered features replace raw data completely
Assuming engineered features reduce dataset size
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.