Retrieving Data from the New York Times Books API
In this analysis, data was retrieved from the New
York Times Books API, which provides access to top 5 books for all
the Best Sellers lists for specified date and related metadata. The API
allows users to fetch information about books, lists, and rankings.
# Load necessary libraries
library(jsonlite) # For JSON processing
library("dplyr")
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(knitr)
# Load the JSON file
books_json <- fromJSON("C:/Users/ninan/iCloudDrive/Study/CUNY/607 Data Acquisition and Management/w9/best_selling_books.json")
# Extract the list ids from the results
category_list <- books_json$results$lists
# Selected list Data frame
selected_lists_df <- category_list %>%
select(list_id, list_name)
kable((selected_lists_df), caption = "Books categories")
Books categories
| 704 |
Combined Print and E-Book Fiction |
| 708 |
Combined Print and E-Book Nonfiction |
| 1 |
Hardcover Fiction |
| 2 |
Hardcover Nonfiction |
| 17 |
Trade Fiction Paperback |
| 4 |
Paperback Nonfiction |
| 24 |
Advice How-To and Miscellaneous |
| 13 |
Childrens Middle Grade Hardcover |
| 7 |
Picture Books |
| 10 |
Series Books |
| 14 |
Young Adult Hardcover |
| 301 |
Audio Fiction |
| 302 |
Audio Nonfiction |
| 532 |
Business Books |
| 719 |
Graphic Books and Manga |
| 10018 |
Mass Market Monthly |
| 10015 |
Middle Grade Paperback Monthly |
| 10016 |
Young Adult Paperback Monthly |
# Extract the books list from the results
books_list <- books_json$results$lists$books
# Accessing the first book data frame in the list
books_df1 <- books_list[[1]]
# Selected first book Data frame
selected_books_df1 <- books_df1 %>%
select(author, title)
kable((selected_books_df1), caption = "5 best selling books for Combined Print and E-Book Fiction") # First data frame
5 best selling books for Combined Print and E-Book
Fiction
| Colleen Hoover |
IT STARTS WITH US |
| Colleen Hoover |
IT ENDS WITH US |
| Bonnie Garmus |
LESSONS IN CHEMISTRY |
| Colleen Hoover |
VERITY |
| John Grisham |
THE BOYS FROM BILOXI |
# Combining all data frames into one
all_books_df <- bind_rows(books_list)
# Selected combined Data frame
selected_all_books_df <- all_books_df %>%
select(author, title)
# Display the combined data frame
kable((selected_all_books_df), caption = "5 best selling books for different categories_2013-01-01")
5 best selling books for different
categories_2013-01-01
| Colleen Hoover |
IT STARTS WITH US |
| Colleen Hoover |
IT ENDS WITH US |
| Bonnie Garmus |
LESSONS IN CHEMISTRY |
| Colleen Hoover |
VERITY |
| John Grisham |
THE BOYS FROM BILOXI |
| Michelle Obama |
THE LIGHT WE CARRY |
| Jennette McCurdy |
I’M GLAD MY MOM DIED |
| Matthew Perry |
FRIENDS, LOVERS, AND THE BIG TERRIBLE THING |
| Bono |
SURRENDER |
| Stacy Schiff |
THE REVOLUTIONARY |
| Bonnie Garmus |
LESSONS IN CHEMISTRY |
| John Grisham |
THE BOYS FROM BILOXI |
| Stephen King |
FAIRY TALE |
| Barbara Kingsolver |
DEMON COPPERHEAD |
| Nicholas Sparks |
DREAMLAND |
| Michelle Obama |
THE LIGHT WE CARRY |
| Jennette McCurdy |
I’M GLAD MY MOM DIED |
| Matthew Perry |
FRIENDS, LOVERS, AND THE BIG TERRIBLE THING |
| Bono |
SURRENDER |
| Stacy Schiff |
THE REVOLUTIONARY |
| Colleen Hoover |
IT STARTS WITH US |
| Colleen Hoover |
IT ENDS WITH US |
| Colleen Hoover |
VERITY |
| Colleen Hoover |
UGLY LOVE |
| Delia Owens |
WHERE THE CRAWDADS SING |
| Bessel van der Kolk |
THE BODY KEEPS THE SCORE |
| Robin Wall Kimmerer |
BRAIDING SWEETGRASS |
| bell hooks |
ALL ABOUT LOVE |
| Mel Brooks |
ALL ABOUT ME! |
| Michelle Obama |
BECOMING |
| James Clear |
ATOMIC HABITS |
| Harris Faulkner |
FAITH STILL MOVES MOUNTAINS |
| Ina Garten |
GO-TO DINNERS |
| David Goggins |
NEVER FINISHED |
| Charlie Mackesy |
THE BOY, THE MOLE, THE FOX AND THE HORSE |
| America’s Test Kitchen Kids |
THE COMPLETE COOKBOOK FOR YOUNG CHEFS |
| J.K. Rowling. |
THE CHRISTMAS PIG |
| America’s Test Kitchen Kids |
THE COMPLETE BAKING BOOK FOR YOUNG CHEFS |
| Joanna Farrow |
THE OFFICIAL HARRY POTTER BAKING BOOK |
| Katherine Applegate. |
ODDER |
| Adam Wallace. |
HOW TO CATCH AN ELF |
| Adam Rubin. |
DRAGONS LOVE TACOS |
| Drew Daywalt. |
THE DAY THE CRAYONS QUIT |
| Erin Guendelsberger. |
LITTLE RED SLEIGH |
| Sherri Duskey Rinker. |
CONSTRUCTION SITE ON CHRISTMAS NIGHT |
| and Jeff Kinney |
DIARY OF A WIMPY KID |
| J.K. Rowling |
HARRY POTTER |
| Rick Riordan |
PERCY JACKSON & THE OLYMPIANS |
| Holly Jackson |
A GOOD GIRL’S GUIDE TO MURDER |
| Mary Pope Osborne. |
MAGIC TREE HOUSE |
| Shea Ernshaw |
LONG LIVE THE PUMPKIN QUEEN |
| Holly Jackson |
FIVE SURVIVE |
| Adam Silvera |
THE FIRST TO DIE AT THE END |
| Alex Aster |
LIGHTLARK |
| Karen M. McManus |
ONE OF US IS LYING |
| Stephen King |
FAIRY TALE |
| Bonnie Garmus |
LESSONS IN CHEMISTRY |
| Colleen Hoover |
IT STARTS WITH US |
| John Grisham |
THE BOYS FROM BILOXI |
| Barbara Kingsolver |
DEMON COPPERHEAD |
| Michelle Obama |
THE LIGHT WE CARRY |
| Jennette McCurdy |
I’M GLAD MY MOM DIED |
| Matthew Perry |
FRIENDS, LOVERS, AND THE BIG TERRIBLE THING |
| Bessel van der Kolk |
THE BODY KEEPS THE SCORE |
| Matthew McConaughey |
GREENLIGHTS |
| James Clear |
ATOMIC HABITS |
| Chris Miller |
CHIP WAR |
| Brené Brown |
DARE TO LEAD |
| Jocko Willink and Leif Babin |
EXTREME OWNERSHIP |
| Tori Dunlap |
FINANCIAL FEMINIST |
| Dav Pilkey |
COLLABORATIONS |
| Tui T. Sutherland. |
MOON RISING |
| Tatsuki Fujimoto |
CHAINSAW MAN, VOL. 1 |
| Dav Pilkey |
ON PURPOSE |
| Dav Pilkey |
MOTHERING HEIGHTS |
| John Grisham |
THE JUDGE’S LIST |
| James Patterson and Howard Roughan |
STEAL |
| Danielle Steel |
INVISIBLE |
| David Baldacci |
A GAMBLING MAN |
| Nora Roberts |
THE AWAKENING |
| Barbara O’Connor |
WISH |
| Rosanne Parry. |
A WOLF CALLED WANDER |
| Katherine Applegate. |
THE ONE AND ONLY IVAN |
| Katherine Applegate. |
THE ONE AND ONLY BOB |
| Lisa McMann |
MAP OF FLAMES |
| Kathleen Glasgow |
GIRL IN PIECES |
| Laura Nowlin |
IF HE HAD BEEN WITH ME |
| Adam Silvera |
THEY BOTH DIE AT THE END |
| David Bell |
SHE’S GONE |
| E. Lockhart |
WE WERE LIARS |