4.6.2. Lab#
Use this assignment to practice the chapter’s concepts and coding skills in runnable Python code.
Sign in from the account menu before you start working on the assignment.
Write and run your code directly in the coding cells.
Multiple submissions are allowed. The highest score is kept.
### Question 1: Build a Sales Table
# Import pandas as pd, then build a DataFrame from regions and revenues.
# Store the DataFrame in a variable named sales_df.
# Print exactly:
# Rows: 4
# Columns: 2
regions = ["East", "West", "East", "South"]
revenues = [1200, 950, 1350, 800]
### Your code starts here.
### Your code ends here.
Rows: 4
Columns: 2
### Question 2: Select Labeled Values
# Import pandas as pd, then create a Series from values with labels as its index.
# Store the Series in a variable named scores.
# Print exactly:
# B score: 91
# First score: 82
values = [82, 91, 76]
labels = ["A", "B", "C"]
### Your code starts here.
### Your code ends here.
B score: 91
First score: 82
### Question 3: Detect and Fill Missing Sales
# Import pandas as pd, then create a Series from sales.
# Count missing values with isna(), fill missing values with 0, and total the filled Series.
# Print exactly:
# Missing sales: 1
# Filled total: 215
sales = [120, None, 95]
### Your code starts here.
### Your code ends here.
Missing sales: 1
Filled total: 215
### Question 4: Filter and Sort Orders
# Import pandas as pd, then create a DataFrame with region and revenue columns.
# Keep rows with revenue of at least 1000 and sort from highest to lowest revenue.
# Print exactly:
# High regions: ['North', 'East']
# Top revenue: 1400
orders = [["East", 1250], ["West", 900], ["North", 1400], ["South", 700]]
### Your code starts here.
### Your code ends here.
High regions: ['North', 'East']
Top revenue: 1400
### Question 5: Group Revenue by Region
# Import pandas as pd, then create a DataFrame with region and revenue columns.
# Group by region and sum revenue.
# Print exactly:
# East total: 250
# West total: 200
sales = [["East", 100], ["West", 80], ["East", 150], ["West", 120], ["South", 90]]
### Your code starts here.
### Your code ends here.
East total: 250
West total: 200
Question 1
Question 2
Question 3
Question 4
Question 5