0
0
NumPydata~30 mins

NumPy with Pandas integration - Mini Project: Build & Apply

Choose your learning style9 modes available
NumPy with Pandas integration
📖 Scenario: You work in a small store and want to analyze sales data. You have sales numbers for different products stored in a NumPy array. You want to use Pandas to organize this data with product names and then calculate some statistics.
🎯 Goal: Create a Pandas DataFrame from a NumPy array of sales data with product names as the index. Then calculate the average sales using NumPy functions integrated with Pandas.
📋 What You'll Learn
Create a NumPy array with exact sales data
Create a Pandas DataFrame using the NumPy array and product names
Use a NumPy function to calculate the average sales from the DataFrame
Print the average sales value
💡 Why This Matters
🌍 Real World
Stores and businesses often collect sales data as numbers. Using NumPy and Pandas together helps organize and analyze this data quickly.
💼 Career
Data analysts and scientists use NumPy and Pandas daily to clean, organize, and analyze data for reports and decision making.
Progress0 / 4 steps
1
Create the sales data as a NumPy array
Create a NumPy array called sales_data with these exact values: 100, 150, 200, 130, 170.
NumPy
Need a hint?

Use np.array and pass the list of numbers inside square brackets.

2
Create a Pandas DataFrame with product names
Create a list called products with these exact names: 'Apples', 'Bananas', 'Cherries', 'Dates', 'Elderberries'. Then create a Pandas DataFrame called df using sales_data as the data and products as the index.
NumPy
Need a hint?

Use pd.DataFrame with sales_data as data, products as index, and set column name to 'Sales'.

3
Calculate the average sales using NumPy
Use the NumPy function np.mean() on the 'Sales' column of the DataFrame df to calculate the average sales. Store the result in a variable called average_sales.
NumPy
Need a hint?

Use np.mean() and pass df['Sales'] as the argument.

4
Print the average sales
Print the value of average_sales using a print() statement.
NumPy
Need a hint?

Use print(average_sales) to display the average sales.