Bird
Raised Fist0
Data Analysis Pythondata~20 mins

describe() for statistics in Data Analysis Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Describe Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
Output of describe() on numeric data
What is the output of the describe() method on this DataFrame's numeric column?
Data Analysis Python
import pandas as pd

df = pd.DataFrame({'scores': [10, 20, 20, 30, 40]})
result = df['scores'].describe()
print(result)
A
count    5.0
mean    24.0
std     12.25
min     10.0
25%     15.0
50%     20.0
75%     30.0
max     40.0
Name: scores, dtype: float64
B
count    5
mean    24
std     12.25
min     10
25%     20
50%     20
75%     30
max     40
Name: scores, dtype: int64
C
count    5.0
mean    24.0
std     11.40
min     10.0
25%     20.0
50%     20.0
75%     30.0
max     40.0
Name: scores, dtype: float64
D
count    5.0
mean    24.0
std     10.0
min     10.0
25%     20.0
50%     20.0
75%     30.0
max     40.0
Name: scores, dtype: float64
Attempts:
2 left
💡 Hint
Remember that describe() returns count, mean, std, min, quartiles, and max for numeric data.
❓ data_output
intermediate
2:00remaining
describe() on categorical data output
What does describe() return when applied to a categorical column in a DataFrame?
Data Analysis Python
import pandas as pd

df = pd.DataFrame({'colors': ['red', 'blue', 'red', 'green', 'blue', 'blue']})
result = df['colors'].describe()
print(result)
A
count       6
unique      3
top       blue
freq        3
Name: colors, dtype: object
B
count       6
mean      NaN
std       NaN
min       blue
max       red
Name: colors, dtype: object
C
count       6
unique      4
top       red
freq        2
Name: colors, dtype: object
D
count       6
unique      3
top       green
freq        1
Name: colors, dtype: object
Attempts:
2 left
💡 Hint
For categorical data, describe() shows count, unique values, most frequent value (top), and its frequency (freq).
🧠 Conceptual
advanced
1:30remaining
Understanding describe() output for mixed data
If a DataFrame has both numeric and categorical columns, what does describe() return by default?
AIt returns descriptive statistics only for numeric columns.
BIt returns descriptive statistics for all columns, numeric and categorical combined in one table.
CIt returns descriptive statistics only for categorical columns.
DIt raises an error because of mixed data types.
Attempts:
2 left
💡 Hint
By default, describe() focuses on numeric data unless specified otherwise.
🔧 Debug
advanced
1:30remaining
Error when calling describe() on empty DataFrame
What error occurs when calling describe() on an empty DataFrame with no columns?
Data Analysis Python
import pandas as pd

df = pd.DataFrame()
result = df.describe()
print(result)
AAttributeError: 'DataFrame' object has no attribute 'describe'
B
Empty DataFrame
Columns: []
Index: []
CTypeError: describe() missing 1 required positional argument
DValueError: No objects to describe
Attempts:
2 left
💡 Hint
Check what pandas returns when describe() is called on an empty DataFrame.
🚀 Application
expert
2:30remaining
Using describe() to compare two datasets
You have two DataFrames df1 and df2 with a numeric column 'age'. You want to quickly compare their age distributions. Which code snippet correctly prints the summary statistics side by side?
Data Analysis Python
import pandas as pd

df1 = pd.DataFrame({'age': [23, 45, 31, 35, 40]})
df2 = pd.DataFrame({'age': [30, 22, 40, 50, 60]})
Aprint(df1['age'].describe().merge(df2['age'].describe()))
Bprint(df1['age'].describe() + df2['age'].describe())
Cprint(df1['age'].describe().append(df2['age'].describe()))
Dprint(pd.concat([df1['age'].describe(), df2['age'].describe()], axis=1))
Attempts:
2 left
💡 Hint
Think about how to combine two Series objects side by side in pandas.

Practice

(1/5)
1. What does the describe() function in pandas primarily provide for a DataFrame?
easy
A. A sorted version of the DataFrame
B. A plot of the data distribution
C. A list of all column names
D. A summary of main statistics like mean, median, and count

Solution

  1. Step 1: Understand the purpose of describe()

    The describe() function summarizes key statistics such as count, mean, std, min, max, and quartiles for numeric data.
  2. Step 2: Compare with other options

    Options B, C, and D describe different functions or outputs unrelated to describe().
  3. Final Answer:

    A summary of main statistics like mean, median, and count -> Option D
  4. Quick Check:

    describe() = summary statistics [OK]
Hint: Remember: describe() = quick stats summary [OK]
Common Mistakes:
  • Thinking describe() creates plots
  • Confusing describe() with listing columns
  • Assuming describe() sorts data
2. Which of the following is the correct way to call describe() on a pandas DataFrame named df?
easy
A. df.describe()
B. describe(df)
C. df.describe
D. df.describe[]

Solution

  1. Step 1: Recall pandas method syntax

    Methods are called with parentheses after the method name, so df.describe() is correct.
  2. Step 2: Check other options for syntax errors

    df.describe[] uses invalid square brackets; describe(df) incorrectly calls it as a standalone function; df.describe misses parentheses and prints the method object.
  3. Final Answer:

    df.describe() -> Option A
  4. Quick Check:

    Method call needs () = df.describe() [OK]
Hint: Call methods with parentheses: df.describe() [OK]
Common Mistakes:
  • Forgetting parentheses when calling methods
  • Using square brackets instead of parentheses
  • Trying to call describe as a standalone function
3. Given the DataFrame df below:
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3, 4, 5], 'B': [10, 20, 30, 40, 50]})
print(df.describe())

What is the output for the mean of column A?
medium
A. 3.0
B. 2.5
C. 15.0
D. 10.0

Solution

  1. Step 1: Calculate mean of column A

    Column A has values [1, 2, 3, 4, 5]. Mean = (1+2+3+4+5)/5 = 15/5 = 3.0.
  2. Step 2: Verify other options

    Options B, C, and D do not match the calculated mean.
  3. Final Answer:

    3.0 -> Option A
  4. Quick Check:

    Mean of A = 3.0 [OK]
Hint: Sum values and divide by count for mean [OK]
Common Mistakes:
  • Mixing mean with median or mode
  • Calculating sum instead of mean
  • Using wrong column values
4. You run the code below but get unexpected output:
import pandas as pd
df = pd.DataFrame({'X': [5, 10, 15]})
print(df.describe)

What is the problem and how to fix it?
medium
A. DataFrame missing columns; add more columns
B. describe is not a pandas function; import missing
C. Missing parentheses after describe; fix with df.describe()
D. Syntax error in DataFrame creation

Solution

  1. Step 1: Identify the problem

    The code references df.describe without parentheses, so it prints the method object, not the result.
  2. Step 2: Fix the code

    Add parentheses to call the method: df.describe().
  3. Final Answer:

    Missing parentheses after describe; fix with df.describe() -> Option C
  4. Quick Check:

    Method call needs () = df.describe() [OK]
Hint: Always use () to call methods [OK]
Common Mistakes:
  • Forgetting parentheses on method calls
  • Assuming describe is not a method
  • Thinking DataFrame needs more columns
5. You have a DataFrame df with numeric and categorical columns. You want describe() to include statistics for all columns, not just numeric ones. Which code will achieve this?
hard
A. df.describe(exclude='all')
B. df.describe(include='all')
C. df.describe(numeric_only=True)
D. df.describe(include='numeric')

Solution

  1. Step 1: Understand describe() default behavior

    By default, describe() shows stats only for numeric columns.
  2. Step 2: Use include='all' to get all columns

    Passing include='all' makes describe() summarize numeric and categorical columns.
  3. Step 3: Check other options

    exclude='all' excludes all columns (invalid result); numeric_only=True limits to numeric only; include='numeric' matches default.
  4. Final Answer:

    df.describe(include='all') -> Option B
  5. Quick Check:

    include='all' = all columns summary [OK]
Hint: Use include='all' to describe all columns [OK]
Common Mistakes:
  • Using numeric_only=True to get all columns
  • Confusing include and exclude parameters
  • Passing invalid values to include
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard