Audible Data Cleaning

Data Cleaning is the process of identifying and correcting or removing errors, inaccuracies, and inconsistencies and overall appropriating the data to improve the quality of the data, thereby making it more suitable for analysis. It is a crucial step in the data analysis process as the quality of data directly impacts the validity of the results. It can involve but not limited to:

The Audible dataset is a collection of data related to audiobooks gathered from Audible. It contains data from authors of audiobooks to release dates. The data represents the important details of audiobooks from 1998 till 2025 (pre-planned releases) and it was obtained from Kaggle. A peek into the Audible dataset indicates that there are some errors and inconsistencies which can be corrected using string manipulation techniques along side other data cleaning techniques.

Libraries Used

The tidyverse library is a collection of R packages that can be used in Data Analysis. Some of the packages to be used are the readr for data import, dplyr for data wrangling, stringr for string manipulation to mention a few. Since these packages are housed in the tidyverse. I call this library since it is already installed.

#load libraries
library(knitr)
library(tidyverse)
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   3.5.1     ✔ tibble    3.2.0
✔ lubridate 1.9.2     ✔ tidyr     1.3.1
✔ purrr     1.0.1     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggplot2)
library(lubridate)
library(RColorBrewer)

Data Import

The Audible dataset is a csv file from Kaggle and in order to deep dive into the data I proceeded to import it into RStudio, the IDE for the R Programming Language.

#read in audible csv 
audible<-read_csv("C:/Users/SAMMY/Desktop/Audible/audible_uncleaned.csv")
Rows: 87489 Columns: 8
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (8): name, author, narrator, time, releasedate, language, stars, price

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

A peek into the dataset just to get familiar with what the data is about :

#examine dataset 
kable(head(audible,10)) 
name author narrator time releasedate language stars price
Geronimo Stilton #11 & #12 Writtenby:GeronimoStilton Narratedby:BillLobely 2 hrs and 20 mins 04-08-08 English 5 out of 5 stars34 ratings 468.00
The Burning Maze Writtenby:RickRiordan Narratedby:RobbieDaymond 13 hrs and 8 mins 01-05-18 English 4.5 out of 5 stars41 ratings 820.00
The Deep End Writtenby:JeffKinney Narratedby:DanRussell 2 hrs and 3 mins 06-11-20 English 4.5 out of 5 stars38 ratings 410.00
Daughter of the Deep Writtenby:RickRiordan Narratedby:SoneelaNankani 11 hrs and 16 mins 05-10-21 English 4.5 out of 5 stars12 ratings 615.00
The Lightning Thief: Percy Jackson, Book 1 Writtenby:RickRiordan Narratedby:JesseBernstein 10 hrs 13-01-10 English 4.5 out of 5 stars181 ratings 820.00
The Hunger Games: Special Edition Writtenby:SuzanneCollins Narratedby:TatianaMaslany 10 hrs and 35 mins 30-10-18 English 5 out of 5 stars72 ratings 656.00
Quest for the Diamond Sword Writtenby:WinterMorgan Narratedby:LukeDaniels 2 hrs and 23 mins 25-11-14 English 5 out of 5 stars11 ratings 233.00
The Dark Prophecy Writtenby:RickRiordan Narratedby:RobbieDaymond 12 hrs and 32 mins 02-05-17 English 5 out of 5 stars50 ratings 820.00
Merlin Mission Collection Writtenby:MaryPopeOsborne Narratedby:MaryPopeOsborne 10 hrs and 56 mins 02-05-17 English 5 out of 5 stars5 ratings 1,256.00
The Tyrant’s Tomb Writtenby:RickRiordan Narratedby:RobbieDaymond 13 hrs and 22 mins 24-09-19 English 5 out of 5 stars58 ratings 820.00

Data Cleaning

Author and Narrator Columns

The Author and Narrator columns contain the names of the Authors and Narrators of the Audiobooks.

#select Author and Narrator columns
audible %>% select(author,narrator) %>% head(10) %>%kable()
author narrator
Writtenby:GeronimoStilton Narratedby:BillLobely
Writtenby:RickRiordan Narratedby:RobbieDaymond
Writtenby:JeffKinney Narratedby:DanRussell
Writtenby:RickRiordan Narratedby:SoneelaNankani
Writtenby:RickRiordan Narratedby:JesseBernstein
Writtenby:SuzanneCollins Narratedby:TatianaMaslany
Writtenby:WinterMorgan Narratedby:LukeDaniels
Writtenby:RickRiordan Narratedby:RobbieDaymond
Writtenby:MaryPopeOsborne Narratedby:MaryPopeOsborne
Writtenby:RickRiordan Narratedby:RobbieDaymond

These columns in the dataset have a common issue known as string concatenation errors. This occurs when two or more strings are joined together without appropriate spacing or delimiters. In this case, the names of authors and narrators are concatenated without spaces, making it difficult to distinguish between first and last names.

Additionally, the strings ‘Writtenby:’ and ‘Narratedby:’ are concatenated with the names, adding unnecessary clutter to our data; hence the need to remove unnecessary strings and add spaces between the names using regular expressions.

#author and narrator column cleaned of unwanted characters and spaces added where necessary
audible<-audible %>%mutate_at(vars(author,narrator),
  ~if_else(str_detect(.,"(Writtenby:)|(Narratedby:)"),
        str_replace_all(str_remove(.,"(Writtenby:)|(Narratedby:)|\\d+"),
                        "(?<=[a-z])(?=[A-Z])", " "),
        .)
  )

cross-check

It becomes important to check the content of these columns after performing the operation

audible %>% select(author,narrator) %>% head(5) %>% kable()
author narrator
Geronimo Stilton Bill Lobely
Rick Riordan Robbie Daymond
Jeff Kinney Dan Russell
Rick Riordan Soneela Nankani
Rick Riordan Jesse Bernstein

Time Column

The Time column is the total duration of each audiobook

audible %>% select(time) %>% head(5) %>%kable()
time
2 hrs and 20 mins
13 hrs and 8 mins
2 hrs and 3 mins
11 hrs and 16 mins
10 hrs

It is a column of string datatype and the contents are needed to be extracted and typecasted to numeric values to aid further analysis.

# Create new columns off the time column and typecast to numeric 
audible <- audible %>%
  mutate(
    # Extract hours and minutes into separate columns
    hours = as.numeric(str_extract(time, "\\d+(?=\\s*hr)")),
    minutes = as.numeric(str_extract(time, "\\d+(?=\\s*min)")),
    
    # Convert time to seconds
    time_seconds = case_when(
      str_detect(time, "hrs|hr") & !str_detect(time, "mins|min") ~
        as.numeric(str_extract(time, "\\d+(?=\\s*hr)")) * 3600,
      str_detect(time, "hrs|hr") & str_detect(time, "min|mins") ~
        as.numeric(str_extract(time, "\\d+(?=\\s*hr)")) * 3600 +
        as.numeric(str_extract(time, "\\d+(?=\\s*min)")) * 60,
      str_detect(time, "mins|min") ~
        as.numeric(str_extract(time, "\\d+")) * 60,
      TRUE ~ as.numeric(time)
    )
  )
Warning: There was 1 warning in `mutate()`.
ℹ In argument: `time_seconds = case_when(...)`.
Caused by warning:
! NAs introduced by coercion
NA values

The NA values are introduced because there are some observations that may not have either hours or minutes. In such instances, since there is no hour or minute to extract as the case may be, the newly created ‘hours’ or ‘minutes’ columns return NA. This is a common occurrence in data processing when the expected data is not present in certain observations. And to handle such instances, NA values are replaced with zero

# Handle NA values (if there are cases like "2 hours" with no mins or "45 mins" with no hours)
audible$hours[is.na(audible$hours)] <- 0
audible$minutes[is.na(audible$minutes)] <- 0 

cross-check

audible %>% select(time,hours,minutes,time_seconds) %>% head(6) %>% kable()
time hours minutes time_seconds
2 hrs and 20 mins 2 20 8400
13 hrs and 8 mins 13 8 47280
2 hrs and 3 mins 2 3 7380
11 hrs and 16 mins 11 16 40560
10 hrs 10 0 36000
10 hrs and 35 mins 10 35 38100

Release Date Column

The Release Date Column just as the name implies is the release date of each and every audiobook contained in the dataset.

audible %>% select(releasedate) %>% head(5) %>% kable()
releasedate
04-08-08
01-05-18
06-11-20
05-10-21
13-01-10

It is of string datatype, hence the need to convert to Date in its truest form.

#converted releasedate column of data type string to date as should be
audible$releasedate<- as.Date(audible$releasedate,format="%d-%m-%y")
#Extract the Year COlumn from the releasedate Column
audible<-audible %>%mutate(Year=year(audible$releasedate)) 
str(audible$releasedate)
 Date[1:87489], format: "2008-08-04" "2018-05-01" "2020-11-06" "2021-10-05" "2010-01-13" ...

Stars Column

The Stars Column represents the average rating given by users for a particular audiobook. It has a band of 1 to 5. But during scraping of the data, the rating was scraped into the same column as the stars bringing about a string concatenation error. There should be a separate rating column that represents the number of users who have rated the audiobook.

audible %>% select(stars) %>% head(6)
# A tibble: 6 × 1
  stars                        
  <chr>                        
1 5 out of 5 stars34 ratings   
2 4.5 out of 5 stars41 ratings 
3 4.5 out of 5 stars38 ratings 
4 4.5 out of 5 stars12 ratings 
5 4.5 out of 5 stars181 ratings
6 5 out of 5 stars72 ratings   
#split stars column into Stars and Rating Column,remove unwanted characters and convert columns to numeric 
  audible <- audible %>% 
    separate(stars, into = c("Stars", "Rating"), sep = "out of 5 stars") %>% 
    mutate(
      Stars = as.numeric(str_remove_all(Stars, " ")),
      Rating = as.numeric(str_remove_all(Rating, ",|ratings"))
    ) %>% 
    mutate_at(
      vars(Stars, Rating),
      ~if_else(is.na(.), 0, .)
    )

cross-check

audible %>% select(Stars,Rating) %>% head(7) %>% kable()
Stars Rating
5.0 34
4.5 41
4.5 38
4.5 12
4.5 181
5.0 72
5.0 11

Price Column

The Price column represents the price of the audiobook.

audible %>% select(price) %>% head(10) 
# A tibble: 10 × 1
   price   
   <chr>   
 1 468.00  
 2 820.00  
 3 410.00  
 4 615.00  
 5 820.00  
 6 656.00  
 7 233.00  
 8 820.00  
 9 1,256.00
10 820.00  

This column is of string datatype and it has some unwanted characters such as the , and Free indicating that these books come at no cost at all.

audible %>% select(price) %>% filter(price=="Free")%>% head(3)
# A tibble: 3 × 1
  price
  <chr>
1 Free 
2 Free 
3 Free 

It is imperative to remove these characters and typecast the data type

  audible <- audible %>% mutate(
    price = case_when(
      str_detect(price, ",") ~ as.numeric(str_remove(price, ",")),
      str_detect(price, "Free") ~ as.numeric(str_remove(price, "Free")),
      TRUE ~ as.numeric(price)
    ),price=if_else(is.na(price),0,price)
  )

cross-check

audible %>% select(price) %>% head(10)
# A tibble: 10 × 1
   price
   <dbl>
 1   468
 2   820
 3   410
 4   615
 5   820
 6   656
 7   233
 8   820
 9  1256
10   820

Subsetting Needed Columns

Selecting useful columns

audible %>% select(name:time,hours:time_seconds,releasedate,Year,language,Stars:price) %>% head(10) %>% kable()
name author narrator time hours minutes time_seconds releasedate Year language Stars Rating price
Geronimo Stilton #11 & #12 Geronimo Stilton Bill Lobely 2 hrs and 20 mins 2 20 8400 2008-08-04 2008 English 5.0 34 468
The Burning Maze Rick Riordan Robbie Daymond 13 hrs and 8 mins 13 8 47280 2018-05-01 2018 English 4.5 41 820
The Deep End Jeff Kinney Dan Russell 2 hrs and 3 mins 2 3 7380 2020-11-06 2020 English 4.5 38 410
Daughter of the Deep Rick Riordan Soneela Nankani 11 hrs and 16 mins 11 16 40560 2021-10-05 2021 English 4.5 12 615
The Lightning Thief: Percy Jackson, Book 1 Rick Riordan Jesse Bernstein 10 hrs 10 0 36000 2010-01-13 2010 English 4.5 181 820
The Hunger Games: Special Edition Suzanne Collins Tatiana Maslany 10 hrs and 35 mins 10 35 38100 2018-10-30 2018 English 5.0 72 656
Quest for the Diamond Sword Winter Morgan Luke Daniels 2 hrs and 23 mins 2 23 8580 2014-11-25 2014 English 5.0 11 233
The Dark Prophecy Rick Riordan Robbie Daymond 12 hrs and 32 mins 12 32 45120 2017-05-02 2017 English 5.0 50 820
Merlin Mission Collection Mary Pope Osborne Mary Pope Osborne 10 hrs and 56 mins 10 56 39360 2017-05-02 2017 English 5.0 5 1256
The Tyrant’s Tomb Rick Riordan Robbie Daymond 13 hrs and 22 mins 13 22 48120 2019-09-24 2019 English 5.0 58 820

Data Validity

This is measure to ensure that all columns have the right datatype

audible %>% str()
tibble [87,489 × 13] (S3: tbl_df/tbl/data.frame)
 $ name        : chr [1:87489] "Geronimo Stilton #11 & #12" "The Burning Maze" "The Deep End" "Daughter of the Deep" ...
 $ author      : chr [1:87489] "Geronimo Stilton" "Rick Riordan" "Jeff Kinney" "Rick Riordan" ...
 $ narrator    : chr [1:87489] "Bill Lobely" "Robbie Daymond" "Dan Russell" "Soneela Nankani" ...
 $ time        : chr [1:87489] "2 hrs and 20 mins" "13 hrs and 8 mins" "2 hrs and 3 mins" "11 hrs and 16 mins" ...
 $ releasedate : Date[1:87489], format: "2008-08-04" "2018-05-01" ...
 $ language    : chr [1:87489] "English" "English" "English" "English" ...
 $ Stars       : num [1:87489] 5 4.5 4.5 4.5 4.5 5 5 5 5 5 ...
 $ Rating      : num [1:87489] 34 41 38 12 181 72 11 50 5 58 ...
 $ price       : num [1:87489] 468 820 410 615 820 ...
 $ hours       : num [1:87489] 2 13 2 11 10 10 2 12 10 13 ...
 $ minutes     : num [1:87489] 20 8 3 16 0 35 23 32 56 22 ...
 $ time_seconds: num [1:87489] 8400 47280 7380 40560 36000 ...
 $ Year        : num [1:87489] 2008 2018 2020 2021 2010 ...

Saving the Data

write.csv(audible,"C:/Users/SAMMY/Desktop/Audible/audible_cleaned.csv")

Data Vizzes

Top 5 Authors in Audible

# Filter top 5 authors
top_authors <- audible %>%
  group_by(author) %>%
  summarise(n = n()) %>%
  arrange(n) %>%
  top_n(5)
Selecting by n
# Bar plot of top 5 Audible Authors
ggplot(top_authors, aes(x = reorder(author, n), y = n, fill = author)) +
  geom_bar(stat = "identity") +
   geom_text(aes(label = n), hjust = -0.1, color = "black", size = 3.5) +
  scale_fill_manual(values = c("矢島雅弘,石橋遊"="#FFA000","Smart Reading"="#FFB347","中西貴之,BJ"="#FFC680","div."="#FFDAB3","Online Studio Productions"="#FFEFE0")) +
  coord_flip() +
  labs(x = "Author", y = "Book Count", title = "Top 5 Authors in Audible") +
  theme_classic() +
  theme(legend.position = "none",plot.title = element_text(hjust = 0.5))

Distribution of Star Rating

star_summary <- audible %>%
  group_by(Stars) %>%
  summarise(count = n()) %>%
  arrange(desc(Stars))

# Create the bar plot
ggplot(star_summary, aes(x =reorder(Stars,Stars), y = count)) +
  geom_bar(stat = "identity", fill = "#FFA000", color = "#000000") +
  geom_text(aes(label = count), vjust = -.5,hjust=0.5, color= "black", size = 3.5)+
  labs(x = "Star Rating", y = "Count", title = "Distribution of Star Ratings") +
  theme_classic() +
  theme(plot.title = element_text(hjust = 0.5))

Heatmap of Books Released By Year

unique_years <- unique(audible$Year)
year_summary <- audible %>%
  group_by(Year) %>%
  summarise(count = n()) %>%
  arrange(Year)

# Create heatmap
ggplot(year_summary, aes(x = "", y = Year, fill = count)) +
  geom_tile(color = "white") +
  scale_fill_gradient(low = "linen", high = "#FFA000") +
  geom_text(aes(label = count), vjust = 0.5, hjust = 1,color = "black", size = 2.8,alpha=1)+
  scale_y_continuous(breaks = unique_years)+
  labs(x = "Book Count", y = "Year", title = "Heatmap of Books Released Each Year") +
  theme_classic() +
  theme(plot.title = element_text(hjust = 0.5))

You can access dataset here and source code here

Conclusion

In conclusion, the Audible dataset provides a rich source of information for understanding trends in audiobook releases over the years. The dataset, once cleaned and appropriately processed, offers valuable insights into the distribution and frequency of book releases per year.

The process of extracting the release year from the dates, summarizing the data by year, and visualizing the results in a heatmap, has allowed to effectively explore and understand the temporal patterns in the data.

However, it’s important to note that this is just the beginning. The dataset likely contains many more insights waiting to be discovered. Further analysis could involve exploring other variables in the dataset, examining the relationships between variables.

Overall, the Audible dataset serves as a powerful tool for data-driven decision making in the audiobook industry, and its value is only enhanced through careful data cleaning and analysis. 📚🔍