Course: INS-605: Data Analysis II Lecturer: Sothea HAS, PhD
Objective: In this lab, we will use the cleaned Amazon Product Reviews dataset from Lab 1 to practice interactive visualization with Plotly. You will build individual figures first, then combine selected figures into a small dashboard-style view.
The lab focuses on:
choosing an appropriate chart for a question;
creating interactive Plotly Express figures;
controlling titles, labels, hover information, and axes;
comparing product and customer activity;
visualizing rating distributions and trends over time;
We use the same Kaggle Amazon Product Reviews dataset as Lab 1 a. If you already have the cleaned data DataFrame from Lab 1, you may reuse it or revise it as we go through the questions below.
For this lab, the important columns are:
UserId, ProductId, Score, Time, ProfileName, Summary, and the engineered fields such as date, year, and month.
Code
# If data is already available from Lab 1, keep this cell simple.# Otherwise, run the following code.# %pip install kagglehubimport kagglehubimport pandas as pdimport ospath = kagglehub.dataset_download("arhamrumi/amazon-product-reviews")file_name = [f for f in os.listdir(path) if f.endswith(".csv")][0]data = pd.read_csv(f"{path}/{file_name}")data.head()
0.1. Quick preparation
Use the cleaning work from Lab 1. At minimum, make sure Time is converted to a datetime column named date.
Question A.1. How many observations and variables are available for visualization?
# To do
A.2. This data contains more detailed information that you can inspect.
Drop duplications before and after removing column ProductId. What do you observe?
Group the data by ProductId and UserId, then compute the count the size of each group and sort them in descending order.
Inspect the summary, text, score and time of those reviews. What do you think?
Drop duplicated reviews for each product and keep only those with largest number of HelpfulnessDenominator.
1. First Interactive Plot: Rating Distribution
A dashboard often starts with a simple overview of the target variable.
Question B. What is the distribution of review ratings (Score)?
Create a chart showing the number of reviews for each rating.
Visualization hint: Product IDs are categorical labels. A horizontal bar chart is usually easier to read than a vertical chart when labels are long and there is no size constaint. Otherwise, vertical bar chart can also be use with rotated ticks (tickanlge = ...).
# To do
2.1. Add another dimension
The number of reviews alone does not tell us whether customers are satisfied.
For the top 10 reviewed products, calculate: - number of reviews; - average rating.
Question E. Build a scatter plot where: - x = number of reviews; - y = average rating; - each point represents a product; - point size represents review volume; - hover information includes the product ID.