0
0
SciPydata~30 mins

SciPy with Pandas for data handling - Mini Project: Build & Apply

Choose your learning style9 modes available
SciPy with Pandas for data handling
📖 Scenario: You work as a data analyst for a small company. You have collected sales data for different products over several months. You want to use Pandas to organize the data and SciPy to calculate some statistics like the mean and median sales.
🎯 Goal: Build a simple program that creates a Pandas DataFrame with sales data, sets a threshold for filtering, uses SciPy to calculate statistics on filtered data, and finally prints the results.
📋 What You'll Learn
Create a Pandas DataFrame with exact sales data
Define a sales threshold variable
Use SciPy to calculate mean and median sales above the threshold
Print the calculated mean and median values
💡 Why This Matters
🌍 Real World
Data analysts often combine Pandas for data handling and SciPy for statistical calculations to understand business data better.
💼 Career
Knowing how to filter data and calculate statistics is essential for roles like data analyst, business analyst, and data scientist.
Progress0 / 4 steps
1
Create the sales data DataFrame
Create a Pandas DataFrame called sales_data with these exact columns and values:
'Product': ['Apples', 'Bananas', 'Cherries', 'Dates', 'Elderberries'],
'Month': ['Jan', 'Jan', 'Feb', 'Feb', 'Mar'],
'Sales': [150, 200, 50, 300, 120].
SciPy
Need a hint?

Use pd.DataFrame with a dictionary where keys are column names and values are lists of data.

2
Set the sales threshold
Create a variable called sales_threshold and set it to 100.
SciPy
Need a hint?

Just assign the number 100 to the variable sales_threshold.

3
Calculate mean and median sales above threshold
Import scipy.stats as stats. Then create a variable called filtered_sales that contains only the 'Sales' values from sales_data where sales are greater than sales_threshold. Use stats.tmean to calculate the mean of filtered_sales and store it in mean_sales. Use stats.tmedian to calculate the median of filtered_sales and store it in median_sales.
SciPy
Need a hint?

Use sales_data.loc to filter rows where 'Sales' is greater than sales_threshold. Then use stats.tmean and stats.tmedian on the filtered sales.

4
Print the mean and median sales
Write two print statements to display the mean and median sales. Use print(f"Mean sales: {mean_sales}") and print(f"Median sales: {median_sales}").
SciPy
Need a hint?

Use print with f-strings to show the values of mean_sales and median_sales.