What will be the output of summary.loc['mean', 'salary']?
medium
A. 52000.0
B. SyntaxError
C. 60000.0
D. 57400.0
Solution
Step 1: Calculate the mean of the 'salary' column
Sum salaries: 50000 + 60000 + 45000 + 80000 + 52000 = 287000. Number of entries: 5. Mean = 287000 / 5 = 57400.0.
Step 2: Understand describe() output
The describe() method returns a DataFrame with statistics including 'mean' as an index row. Accessing summary.loc['mean', 'salary'] gives the mean salary value.
Final Answer:
57400.0 -> Option D
Quick Check:
Mean salary = 57400.0 [OK]
Hint: Sum values and divide by count for mean [OK]
Common Mistakes:
Adding incorrectly or missing one value
Confusing mean with median or mode
Using wrong index or column name
4. You run the following code but get an error:
import pandas as pd
data = {'name': ['Alice', 'Bob'], 'age': [25, 30]}
df = pd.DataFrame(data)
print(df.describe())
What is the most likely reason for the error or unexpected output?
medium
A. The describe() method cannot handle string columns by default
B. The DataFrame is missing a numeric column
C. The DataFrame is empty
D. The describe() method requires a parameter
Solution
Step 1: Check DataFrame columns and types
The DataFrame has a string column 'name' and a numeric column 'age'.
Step 2: Understand describe() behavior
By default, describe() summarizes only numeric columns. It ignores string columns unless specified.
Final Answer:
The describe() method cannot handle string columns by default -> Option A
Quick Check:
describe() skips strings by default [OK]
Hint: describe() defaults to numeric columns only [OK]
Common Mistakes:
Expecting describe() to summarize strings automatically
Thinking DataFrame is empty
Assuming describe() needs parameters always
5. You have a DataFrame df with columns ['product', 'price', 'quantity']. You want to quickly find the average price of products that have quantity greater than 10. Which code snippet correctly performs this first data analysis step?
hard
A. df[df['quantity'] > 10]['price'].mean()
B. df['price'].mean(df['quantity'] > 10)
C. df.mean()['price'] > 10
D. df.describe('price' > 10)
Solution
Step 1: Filter rows where quantity > 10
Use df[df['quantity'] > 10] to select only rows with quantity greater than 10.
Step 2: Calculate mean of 'price' column on filtered data
Access the 'price' column of filtered rows and call mean() to get average price.
Final Answer:
df[df['quantity'] > 10]['price'].mean() -> Option A
Quick Check:
Filter then mean() gives correct average [OK]
Hint: Filter first, then calculate mean [OK]
Common Mistakes:
Passing condition inside mean() incorrectly
Using mean() on entire DataFrame without filtering
Wrong syntax for describe()
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.