📖 Scenario: You have just received a small dataset about sales in a store. Before making any decisions or building models, you want to understand what the data looks like. This helps you find mistakes, see patterns, and know what questions to ask next.
🎯 Goal: Learn how to load data into a pandas DataFrame, check its basic structure, and get simple statistics to understand the data better.
📋 What You'll Learn
Use pandas to create and explore data
Create a DataFrame with exact sales data
Add a variable to select columns for exploration
Use pandas methods to get summary statistics
Print the summary statistics as output
💡 Why This Matters
🌍 Real World
Data exploration helps you understand new data before making decisions or building models. It reveals patterns, errors, and important features.
💼 Career
Data scientists and analysts always start with data exploration to ensure data quality and to guide further analysis or machine learning.
Progress0 / 4 steps
1
Create the sales data DataFrame
Create a pandas DataFrame called sales_data with these exact columns and values: 'Product': ['Apple', 'Banana', 'Carrot', 'Date', 'Eggplant'], 'Price': [0.5, 0.3, 0.2, 1.0, 1.5], 'Quantity': [30, 45, 25, 10, 5]
Pandas
Hint
Use pd.DataFrame with a dictionary where keys are column names and values are lists of data.
2
Select columns to explore
Create a variable called columns_to_explore and set it to a list containing the exact strings 'Price' and 'Quantity'.
Pandas
Hint
Just create a list with the two column names as strings.
3
Get summary statistics for selected columns
Use the describe() method on sales_data[columns_to_explore] and save the result in a variable called summary_stats.
Pandas
Hint
Use sales_data[columns_to_explore].describe() to get statistics like mean, min, max.
4
Print the summary statistics
Print the variable summary_stats to see the summary statistics of the selected columns.
Pandas
Hint
Use print(summary_stats) to display the statistics.
Practice
(1/5)
1. Why is data exploration important before starting analysis with pandas?
easy
A. It automatically cleans the data for you.
B. It helps understand the data and find issues early.
C. It creates visualizations without any code.
D. It speeds up the computer's processing power.
Solution
Step 1: Understand the purpose of data exploration
Data exploration is done to get to know the data, its structure, and any problems it may have.
Step 2: Identify what data exploration does not do
It does not clean data automatically, create visualizations by itself, or affect computer speed.
Final Answer:
It helps understand the data and find issues early. -> Option B
Quick Check:
Data exploration = Understand data [OK]
Hint: Remember: Explore first to know your data well [OK]
Common Mistakes:
Thinking exploration cleans data automatically
Confusing exploration with visualization
Believing it improves computer speed
2. Which pandas command shows the first 5 rows of a DataFrame named df?
easy
A. df.head()
B. df.info()
C. df.describe()
D. df.tail()
Solution
Step 1: Recall pandas commands for viewing data
head() shows the first rows, tail() shows last rows, describe() summarizes statistics, info() shows data info.
Step 2: Match command to requirement
To see first 5 rows, df.head() is correct.
Final Answer:
df.head() -> Option A
Quick Check:
First rows = head() [OK]
Hint: head() = first rows, tail() = last rows [OK]
Common Mistakes:
Using tail() to see first rows
Confusing describe() with head()
Using info() to view data rows
3. Given the code:
import pandas as pd
data = {'age': [25, 30, 22, 40], 'score': [88, 92, 85, 95]}
df = pd.DataFrame(data)
print(df.describe())
What will be the output?
medium
A. Summary statistics including count, mean, std, min, max for each column
B. The first 5 rows of the DataFrame
C. Information about data types and memory usage
D. An error because describe() needs numeric data only
Solution
Step 1: Understand what df.describe() does
It calculates summary statistics like count, mean, std, min, max for numeric columns.
Step 2: Check the data types in df
Both 'age' and 'score' are numeric lists, so describe() works and outputs stats.
Final Answer:
Summary statistics including count, mean, std, min, max for each column -> Option A