1. Introduction

E-commerce platforms offer a wide variety of products across different categories. Understanding the distribution of products across categories helps online businesses identify popular product categories and improve product visibility.

This project analyses the Brazilian E-Commerce Public Dataset by Olist using R programming.

2. Student Details

3. Objectives

  1. Import the Olist products dataset into R.
  2. Examine the structure of the dataset.
  3. Identify and remove missing product category values.
  4. Count the number of products in each category.
  5. Identify the top five product categories.
  6. Visualize the results using a bar chart.

4. Dataset Description

The dataset used in this project is olist_products_dataset.csv.

It contains product information such as product ID, product category, product dimensions, weight, and other product attributes.

5. Data Loading and Inspection

library(ggplot2)

products <- read.csv(
  "olist_products_dataset.csv",
  stringsAsFactors = FALSE,
  na.strings = c("", "NA")
)

head(products)
##                         product_id product_category_name product_name_lenght
## 1 1e9e8ef04dbcff4541ed26657ea517e5            perfumaria                  40
## 2 3aa071139cb16b67ca9e5dea641aaa2f                 artes                  44
## 3 96bd76ec8810374ed1b65e291975717f         esporte_lazer                  46
## 4 cef67bcfe19066a932b7673e239eb23d                 bebes                  27
## 5 9dc1a7de274444849c219cff195d0b71 utilidades_domesticas                  37
## 6 41d3672d4792049fa1779bb35283ed13 instrumentos_musicais                  60
##   product_description_lenght product_photos_qty product_weight_g
## 1                        287                  1              225
## 2                        276                  1             1000
## 3                        250                  1              154
## 4                        261                  1              371
## 5                        402                  4              625
## 6                        745                  1              200
##   product_length_cm product_height_cm product_width_cm
## 1                16                10               14
## 2                30                18               20
## 3                18                 9               15
## 4                26                 4               26
## 5                20                17               13
## 6                38                 5               11
dim(products)
## [1] 32951     9
str(products)
## 'data.frame':    32951 obs. of  9 variables:
##  $ product_id                : chr  "1e9e8ef04dbcff4541ed26657ea517e5" "3aa071139cb16b67ca9e5dea641aaa2f" "96bd76ec8810374ed1b65e291975717f" "cef67bcfe19066a932b7673e239eb23d" ...
##  $ product_category_name     : chr  "perfumaria" "artes" "esporte_lazer" "bebes" ...
##  $ product_name_lenght       : int  40 44 46 27 37 60 56 56 57 36 ...
##  $ product_description_lenght: int  287 276 250 261 402 745 1272 184 163 1156 ...
##  $ product_photos_qty        : int  1 1 1 1 4 1 4 2 1 1 ...
##  $ product_weight_g          : int  225 1000 154 371 625 200 18350 900 400 600 ...
##  $ product_length_cm         : int  16 30 18 26 20 38 70 40 27 17 ...
##  $ product_height_cm         : int  10 18 9 4 17 5 24 8 13 10 ...
##  $ product_width_cm          : int  14 20 15 26 13 11 44 40 17 12 ...
summary(products)
##      product_id    product_category_name product_name_lenght
##  Length   :32951   Length   :32951       Min.   : 5.00      
##  N.unique :32951   N.unique :   73       1st Qu.:42.00      
##  N.blank  :    0   N.blank  :    0       Median :51.00      
##  Min.nchar:   32   Min.nchar:    3       Mean   :48.48      
##  Max.nchar:   32   Max.nchar:   46       3rd Qu.:57.00      
##                    NAs      :  610       Max.   :76.00      
##                                          NAs    :610        
##  product_description_lenght product_photos_qty product_weight_g
##  Min.   :   4.0             Min.   : 1.000     Min.   :    0   
##  1st Qu.: 339.0             1st Qu.: 1.000     1st Qu.:  300   
##  Median : 595.0             Median : 1.000     Median :  700   
##  Mean   : 771.5             Mean   : 2.189     Mean   : 2276   
##  3rd Qu.: 972.0             3rd Qu.: 3.000     3rd Qu.: 1900   
##  Max.   :3992.0             Max.   :20.000     Max.   :40425   
##  NAs    :610                NAs    :610        NAs    :2       
##  product_length_cm product_height_cm product_width_cm
##  Min.   :  7.00    Min.   :  2.00    Min.   :  6.0   
##  1st Qu.: 18.00    1st Qu.:  8.00    1st Qu.: 15.0   
##  Median : 25.00    Median : 13.00    Median : 20.0   
##  Mean   : 30.82    Mean   : 16.94    Mean   : 23.2   
##  3rd Qu.: 38.00    3rd Qu.: 21.00    3rd Qu.: 30.0   
##  Max.   :105.00    Max.   :105.00    Max.   :118.0   
##  NAs    :2         NAs    :2         NAs    :2

6. Data Cleaning

The product category column is cleaned by removing extra spaces and handling missing or empty values.

products$product_category_name <-
  trimws(products$product_category_name)

products$product_category_name[
  products$product_category_name == ""
] <- NA

products_clean <- products[
  !is.na(products$product_category_name),
]

cat("Original rows:", nrow(products), "\n")
## Original rows: 32951
cat("Rows after cleaning:", nrow(products_clean), "\n")
## Rows after cleaning: 32341
cat("Rows removed:",
    nrow(products) - nrow(products_clean), "\n")
## Rows removed: 610
cat("Missing categories after cleaning:",
    sum(is.na(products_clean$product_category_name)))
## Missing categories after cleaning: 0

7. Product Category Analysis

The number of products in each category is calculated using the table() function.

category_counts <- as.data.frame(
  table(products_clean$product_category_name)
)

names(category_counts) <- c(
  "Product_Category",
  "Product_Count"
)

category_counts <- category_counts[
  order(-category_counts$Product_Count),
]

head(category_counts, 10)
##          Product_Category Product_Count
## 14        cama_mesa_banho          3029
## 33          esporte_lazer          2867
## 55       moveis_decoracao          2657
## 12           beleza_saude          2444
## 73  utilidades_domesticas          2335
## 9              automotivo          1900
## 45 informatica_acessorios          1639
## 13             brinquedos          1411
## 67     relogios_presentes          1329
## 71              telefonia          1134

8. Top Five Product Categories

top5 <- head(category_counts, 5)

knitr::kable(
  top5,
  caption = "Top 5 Popular Product Categories"
)
Top 5 Popular Product Categories
Product_Category Product_Count
14 cama_mesa_banho 3029
33 esporte_lazer 2867
55 moveis_decoracao 2657
12 beleza_saude 2444
73 utilidades_domesticas 2335

9. Data Visualization

A horizontal bar chart is created using ggplot2 to display the five categories with the highest number of products.

p <- ggplot(
  top5,
  aes(
    x = reorder(Product_Category, Product_Count),
    y = Product_Count
  )
) +
  geom_col(fill = "steelblue") +
  coord_flip() +
  labs(
    title = "Top 5 Popular Product Categories",
    subtitle = "Based on the number of listed products",
    x = "Product Category",
    y = "Number of Products"
  ) +
  theme_minimal()

print(p)

10. Findings

The analysis identifies the five product categories with the highest number of listed products.

The results show that product distribution varies across categories. These findings can help an online store understand which categories have a larger product selection.

11. Recommendations

  1. Highlight categories with a large number of listed products.
  2. Improve product organization and category navigation.
  3. Monitor product distribution to support inventory planning.
  4. Use category-level analysis to improve the shopping experience.

12. Conclusion

This project analysed product categories in the Olist e-commerce dataset using R programming.

Missing product category values were removed, product counts were calculated, and the top five categories were identified and visualized using ggplot2.

The project demonstrates the use of data cleaning, data manipulation, analysis, and visualization in R.

13. Future Scope

Further analysis can include customer preferences, product reviews, sales performance, and order trends to gain deeper insights into e-commerce operations.

14. References