0
0
Data Analysis Pythondata~15 mins

Why time-based analysis reveals trends in Data Analysis Python - See It in Action

Choose your learning style9 modes available
Why time-based analysis reveals trends
📖 Scenario: Imagine you run a small online store. You want to understand how your sales change over time to spot trends and make better decisions.
🎯 Goal: You will create a simple sales record, set a time threshold, filter sales after that time, and then display the filtered sales to see the trend.
📋 What You'll Learn
Create a dictionary with sales dates as keys and sales amounts as values
Create a variable to hold a date threshold
Use a dictionary comprehension to filter sales after the threshold date
Print the filtered sales dictionary
💡 Why This Matters
🌍 Real World
Businesses often analyze sales or user activity over time to spot trends and make decisions.
💼 Career
Data analysts and scientists use time-based filtering to prepare data for trend analysis and forecasting.
Progress0 / 4 steps
1
Create sales data dictionary
Create a dictionary called sales with these exact entries: '2024-01-01': 150, '2024-02-01': 200, '2024-03-01': 250, '2024-04-01': 300, '2024-05-01': 350
Data Analysis Python
Hint

Use curly braces to create a dictionary with date strings as keys and numbers as values.

2
Set the date threshold
Create a variable called threshold_date and set it to the string '2024-03-01'
Data Analysis Python
Hint

Assign the string '2024-03-01' to the variable threshold_date.

3
Filter sales after the threshold date
Create a new dictionary called filtered_sales using a dictionary comprehension that includes only the sales from sales where the date is greater than or equal to threshold_date
Data Analysis Python
Hint

Use a dictionary comprehension with for date, amount in sales.items() and an if condition to filter.

4
Display the filtered sales
Write a print statement to display the filtered_sales dictionary
Data Analysis Python
Hint

Use print(filtered_sales) to show the filtered dictionary.