C. Summary statistics for columns A and B only, excluding C
D. Only the count of rows
Solution
Step 1: Understand what df.describe() does
It provides summary stats (count, mean, std, min, max, quartiles) for numeric columns only by default.
Step 2: Check the DataFrame columns
Columns A and B are numeric (int and float), C is string (non-numeric), so C is excluded.
Final Answer:
Summary statistics for columns A and B only, excluding C -> Option C
Quick Check:
describe() skips non-numeric columns by default [OK]
Hint: describe() shows stats only for numeric columns by default [OK]
Common Mistakes:
Expecting describe() to include string columns
Thinking describe() throws error on strings
Assuming describe() shows only count
4. You run the code below and get an error:
import pandas as pd
data = {'X': [10, 20, 30], 'Y': [5, 15, 25]}
df = pd.DataFrame(data)
print(df.dtypes())
What is the cause of the error?
medium
A. dtypes is an attribute, not a method, so parentheses cause error
B. DataFrame columns have mixed types
C. DataFrame is empty
D. Missing import statement for pandas
Solution
Step 1: Identify the error source
The code calls df.dtypes() with parentheses, but dtypes is an attribute, not a method.
Step 2: Understand correct usage
Correct usage is df.dtypes without parentheses to access data types.
Final Answer:
dtypes is an attribute, not a method, so parentheses cause error -> Option A
Quick Check:
Use df.dtypes without () [OK]
Hint: Remember dtypes is attribute, no parentheses [OK]
Common Mistakes:
Adding parentheses to dtypes
Assuming error is from missing import
Thinking DataFrame is empty
5. You have a DataFrame df with columns: Age (int), Salary (float), and Department (string). You want to quickly check how many rows and columns it has, the data types of each column, and summary statistics for numeric columns. Which sequence of commands gives you all this information?
hard
A. df.columns; df.dtypes; df.tail()
B. df.describe(); df.shape; df.columns
C. df.info(); df.head(); df.describe()
D. df.shape; df.dtypes; df.describe()
Solution
Step 1: Identify commands for each info type
df.shape gives rows and columns count, df.dtypes shows data types, and df.describe() gives summary stats for numeric columns.
Step 2: Check options for correct sequence
df.shape; df.dtypes; df.describe() lists these three commands in order, so it provides all required info.