π 20 points available
βοΈ Last updated on 9/16/2025
βΆοΈ First, run the code cell below to import unittest, a module used for π§ Check Your Work sections and the autograder.
# DO NOT MODIFY THE CODE IN THIS CELL
import unittest
tc = unittest.TestCase()π― Challenge 1: Import Pandas and NumPyΒΆ
π TasksΒΆ
βοΈ Import the following Python packages.
pandas: Use aliaspd.numpy: Use aliasnp.
# YOUR CODE BEGINS
# YOUR CODE ENDSπ§ Check Your WorkΒΆ
Run the code cell below to test your solution.
βοΈ If the code cell runs without errors, youβre good to move on.
β If the code cell produces an error, review your code and fix any mistakes.
_test_case = "import-pandas-numpy"
_points = 5
tc.assertTrue(
"pd" in globals(), "Check whether you have correctly import Pandas with an alias."
)
tc.assertTrue(
"np" in globals(), "Check whether you have correctly import NumPy with an alias."
)π― Challenge 2: Create a Pandas SeriesΒΆ
π TasksΒΆ
βοΈ Create a new Pandas
Seriesnamedsample_serieswith the following four values:-20,-10,10,20
π HintΒΆ
The code below creates a new Pandas Series with the values 1 and 2.
my_new_series = pd.Series([1, 2])# YOUR CODE BEGINS
# YOUR CODE ENDS
print(sample_series)π§ Check Your WorkΒΆ
Run the code cell below to test your solution.
βοΈ If the code cell runs without errors, youβre good to move on.
β If the code cell produces an error, review your code and fix any mistakes.
_test_case = "create-a-pandas-series"
_points = 5
pd.testing.assert_series_equal(sample_series, pd.Series(x * 10 for x in [-2, -1, 1, 2]))π― Challenge 3: Create a Pandas DataFrameΒΆ
π TasksΒΆ
βοΈ You are given two lists -
brandsandrankingsthat contain the names of make-up products and the number of reviews on Sephora.com.βοΈ Using the two lists, create a new Pandas
DataFramenameddf_brandsthat has the following two columns:brand: Names of the brandsranking: Ranking of the brands
βοΈ Note that the column names are singular.
π HintΒΆ
The code below creates a new Pandas DataFrame from two series.
my_new_dataframe = pd.DataFrame({
"column_one": my_series1,
"column_two": my_series2
})π Expected OutputΒΆ
| brand | ranking | |
|---|---|---|
| 0 | Apple | 1 |
| 1 | Amazon | 2 |
| 2 | 3 |
brands = ["Apple", "Amazon", "Google"]
rankings = [1, 2, 3]
# YOUR CODE BEGINS
# YOUR CODE ENDS
display(df_brands)π§ Check Your WorkΒΆ
Run the code cell below to test your solution.
βοΈ If the code cell runs without errors, youβre good to move on.
β If the code cell produces an error, review your code and fix any mistakes.
_test_case = "create-a-pandas-dataframe-1"
_points = 5
pd.testing.assert_frame_equal(
df_brands.reset_index(drop=True),
pd.DataFrame(
{"brand": {0: "Apple", 1: "Amazon", 2: "Google"}, "ranking": {0: 1, 1: 2, 2: 3}}
),
)π― Challenge 4: Create a Pandas DataFrameΒΆ
π TasksΒΆ
βοΈ You are given two lists -
product_namesandnum_reviewsthat contain the names of make-up products and the number of reviews on Sephora.com.βοΈ Using the two lists, create a new Pandas
DataFramenameddf_top_productsthat has the following two columns:"product_name": Names of the products"num_review": Number of reviews
βοΈ Note that the column names are singular.
π HintΒΆ
The code below creates a new Pandas DataFrame from two series.
my_new_dataframe = pd.DataFrame({
"column_one": my_series1,
"column_two": my_series2
})product_names = [
"Laneige Lip Sleeping Mask",
"The Ordinary Hyaluronic Acid 2% + B5",
"Laneige Lip Glowy Balm",
"Chanel COCO MADEMOISELLE Eau de Parfum",
]
num_reviews = [12715, 2274, 2766, 724]
# YOUR CODE BEGINS
# YOUR CODE ENDS
display(df_top_products)π§ Check Your WorkΒΆ
Run the code cell below to test your solution.
βοΈ If the code cell runs without errors, youβre good to move on.
β If the code cell produces an error, review your code and fix any mistakes.
_test_case = "create-a-pandas-dataframe-2"
_points = 5
pd.testing.assert_frame_equal(
df_top_products.reset_index(drop=True),
pd.DataFrame(
{
"product_name": {
0: "Laneige Lip Sleeping Mask",
1: "The Ordinary Hyaluronic Acid 2% + B5",
2: "Laneige Lip Glowy Balm",
3: "Chanel COCO MADEMOISELLE Eau de Parfum",
},
"num_review": {0: 12715, 1: 2274, 2: 2766, 3: 724},
}
),
)