0
0
Pandasdata~15 mins

Series as labeled one-dimensional array in Pandas - Mini Project: Build & Apply

Choose your learning style9 modes available
Series as labeled one-dimensional array
📖 Scenario: You are working with sales data for a small shop. Each product has a sales number for the day. You want to organize this data in a way that keeps the product names linked to their sales numbers.
🎯 Goal: Create a pandas Series to hold sales numbers with product names as labels. Then, select and display the sales number for a specific product.
📋 What You'll Learn
Create a pandas Series named sales with exact product names and sales numbers
Create a variable product_name to hold the product to look up
Use the product_name variable to get the sales number from the sales Series
Print the sales number for the selected product
💡 Why This Matters
🌍 Real World
Stores and businesses often track sales data by product. Using labeled data structures like pandas Series helps keep data clear and easy to analyze.
💼 Career
Data analysts and scientists use pandas Series to manage and analyze labeled data efficiently in many industries.
Progress0 / 4 steps
1
Create the sales data Series
Import pandas as pd. Create a pandas Series called sales with these exact entries: 'Apples': 30, 'Bananas': 45, 'Oranges': 25, 'Grapes': 40.
Pandas
Need a hint?

Use pd.Series with a dictionary where keys are product names and values are sales numbers.

2
Set the product name to look up
Create a variable called product_name and set it to the string 'Bananas'.
Pandas
Need a hint?

Just assign the string 'Bananas' to the variable product_name.

3
Get the sales number for the product
Use the product_name variable to get the sales number from the sales Series and store it in a variable called sales_number.
Pandas
Need a hint?

Use square brackets with sales[product_name] to get the value for the label stored in product_name.

4
Print the sales number
Print the variable sales_number to display the sales for the selected product.
Pandas
Need a hint?

Use print(sales_number) to show the sales number.