📖 Scenario: You work in a small bakery. You have sales data for different types of bread sold each day. You want to understand the basic statistics of daily sales to plan better.
🎯 Goal: Learn how to use the describe() method in pandas to get quick statistics like mean, median, min, max, and quartiles for your sales data.
📋 What You'll Learn
Create a pandas DataFrame with daily sales data
Use the describe() method to get summary statistics
Print the summary statistics
💡 Why This Matters
🌍 Real World
Businesses often need to quickly understand their sales or production data to make decisions. Using describe() helps get a quick overview of key statistics.
💼 Career
Data analysts and scientists use describe() to summarize datasets before deeper analysis or reporting.
Progress0 / 4 steps
1
Create the sales data DataFrame
Import pandas as pd and create a DataFrame called sales_data with these exact columns and values: 'Day': ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday'], 'Bread': [30, 45, 50, 40, 60], 'Pastry': [20, 25, 30, 22, 28]
Data Analysis Python
Hint
Use pd.DataFrame() with a dictionary where keys are column names and values are lists of data.
2
Set the Day column as index
Create a new DataFrame called sales_indexed by setting the 'Day' column as the index of sales_data using the set_index() method.
Data Analysis Python
Hint
Use set_index('Day') on the DataFrame to make 'Day' the index.
3
Get summary statistics with describe()
Use the describe() method on sales_indexed and save the result to a variable called summary_stats.
Data Analysis Python
Hint
Call describe() on the DataFrame to get statistics like mean, min, max, and quartiles.
4
Print the summary statistics
Print the variable summary_stats to display the statistics of the sales data.
Data Analysis Python
Hint
Use print(summary_stats) to show the statistics.
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
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.
Step 2: Compare with other options
Options B, C, and D describe different functions or outputs unrelated to describe().
Final Answer:
A summary of main statistics like mean, median, and count -> Option D
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
Step 1: Recall pandas method syntax
Methods are called with parentheses after the method name, so df.describe() is correct.
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.
Final Answer:
df.describe() -> Option A
Quick Check:
Method call needs () = df.describe() [OK]
Hint: Call methods with parentheses: df.describe() [OK]
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
Step 1: Identify the problem
The code references df.describe without parentheses, so it prints the method object, not the result.
Step 2: Fix the code
Add parentheses to call the method: df.describe().
Final Answer:
Missing parentheses after describe; fix with df.describe() -> Option C
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
Step 1: Understand describe() default behavior
By default, describe() shows stats only for numeric columns.
Step 2: Use include='all' to get all columns
Passing include='all' makes describe() summarize numeric and categorical columns.
Step 3: Check other options
exclude='all' excludes all columns (invalid result); numeric_only=True limits to numeric only; include='numeric' matches default.
Final Answer:
df.describe(include='all') -> Option B
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 unknownstrongwhile earning +1 Grip toward your certificate.