Q1. What are the questions that a data scientist can ask on Covid-19 data? Think of some good questions and then categorize your questions as descriptive, exploratory, inferential and predictive.
Answer:
Descriptive Questions . Is there any vaccine out there to prevent Covid-19? . From which country the Covid-19 disease had spread? . What are the symptoms for being Covid-19 positive? . When did the Covid-19 pandemic start?
Exploratory Questions . What are the top countries affected by Covid-19? . Which country has been mostly affected by Covid-19? . Does crowded place simply have more possibility to get affected by Covid-19?
Inferential Questions . Does wearing masks help to lower the spread of Covid-19? . Does spraying people with disinfectant lower the spread of Covid-19? . Is hand sanitizer effective against Covid-19? . Is it really possible to make any effective vaccine for Covid-19?
Predictive Questions . If someone is Covid-19 positive, will he/she surely die? . If I vape tobacco or nicotine am I at risk for complications from COVID-19?
Q2.Web scraping with R
Goto this URL and follow the instruction on web scraping: https://medium.freecodecamp.org/an-introduction-to-web-scraping-using-r-40284110c848
Show that you had successfully done some web scraping.
You may use the “Scrape product details from Amazon” (mentioned in the URL) or any other example that you find online.
Submit on Spectrum for Tutorial 3.
library(xml2)
library(rvest)
library(stringr)
library(jsonlite)
webpage<-read_html("https://www.amazon.in/OnePlus-Nord-Gray-128GB-Storage/dp/B08695ZSP6/ref=sr_1_4?dchild=1&keywords=oneplus+7&qid=1604763563&s=electronics&sr=1-4")
html_title<-html_nodes(webpage, 'h1#title')
title<-html_text(html_title)
head(title)
## [1] "\n\n\n\n\n\n\n\n\nOnePlus Nord 5G (Gray Onyx, 8GB RAM, 128GB Storage)\n\n\n\n\n\n\n\n\n\n\n\n\n"
str_replace_all(title, "[\r\n]" , "")
## [1] "OnePlus Nord 5G (Gray Onyx, 8GB RAM, 128GB Storage)"
price_html<-html_nodes(webpage, 'span#priceblock_dealprice')
price <- html_text(price_html)
str_replace_all(price, "[\r\n]" , "")
## character(0)
head(price)
## character(0)
desc_html <- html_nodes(webpage, 'div#productDescription')
desc <- html_text(desc_html)
desc <- str_replace_all(desc, "[\r\n\t]" , "")
desc <- str_trim(desc)
head(desc)
## [1] "Style name:8GB RAM + 128GB Storage | Colour:Gray OnyxNord, the latest product line by the Number 1 premium smartphone in India - OnePlus, brings together Exceptional Cameras, Smooth Experience and OnePlus Quality and Trust to the consumers. Nord comes with the same 48 MP Sony IMX586 sensor as the OnePlus 8 to reduce blur and shakiness from photos and video clips. It also boasts an 8 MP ultra wide angle so you can always fit in one more person, and one more and one more, in addition to the 32MP main shooter. OnePlus' legacy of smooth experience is also passed to Nord with 90Hz fluid AMOLED display and Oxygen OS. Nord is powered by the Qualcomm Snapdragon 765G 5G mobile platform which enables improved CPU speeds, 10% faster graphics rendering and delivers peak gaming performance. In other words, Nord is a fast phone. Dragon fast. OnePlus Nord Pretty much everything you could ask for"
rate_html <- html_nodes(webpage, 'span#acrPopover')
rate <- html_text(rate_html)
rate <- str_replace_all(rate, "[\r\n]" , "")
rate <- str_trim(rate)
rate<-rate[1]
head(rate)
## [1] "4.1 out of 5 stars"
size_html <- html_nodes(webpage, 'div#variation_style_name')
size_html <- html_nodes(size_html, 'span.selection')
size <- html_text(size_html)
size <- str_trim(size)
head(size)
## [1] "8GB RAM + 128GB Storage"
color_html <- html_nodes(webpage, 'div#variation_color_name')
color_html <- html_nodes(color_html, 'span.selection')
color <- html_text(color_html)
color <- str_trim(color)
head(color)
## [1] "Gray Onyx"
product_data <- data.frame(Title = title, Description = desc, Rating = rate, Size = size, Color = color)
str(product_data)
## 'data.frame': 1 obs. of 5 variables:
## $ Title : chr "\n\n\n\n\n\n\n\n\nOnePlus Nord 5G (Gray Onyx, 8GB RAM, 128GB Storage)\n\n\n\n\n\n\n\n\n\n\n\n\n"
## $ Description: chr "Style name:8GB RAM + 128GB Storage | Colour:Gray OnyxNord, the latest product line by the Number 1 premium smar"| __truncated__
## $ Rating : chr "4.1 out of 5 stars"
## $ Size : chr "8GB RAM + 128GB Storage"
## $ Color : chr "Gray Onyx"
json_data <- toJSON(product_data)
cat(json_data)
## [{"Title":"\n\n\n\n\n\n\n\n\nOnePlus Nord 5G (Gray Onyx, 8GB RAM, 128GB Storage)\n\n\n\n\n\n\n\n\n\n\n\n\n","Description":"Style name:8GB RAM + 128GB Storage | Colour:Gray OnyxNord, the latest product line by the Number 1 premium smartphone in India - OnePlus, brings together Exceptional Cameras, Smooth Experience and OnePlus Quality and Trust to the consumers. Nord comes with the same 48 MP Sony IMX586 sensor as the OnePlus 8 to reduce blur and shakiness from photos and video clips. It also boasts an 8 MP ultra wide angle so you can always fit in one more person, and one more and one more, in addition to the 32MP main shooter. OnePlus' legacy of smooth experience is also passed to Nord with 90Hz fluid AMOLED display and Oxygen OS. Nord is powered by the Qualcomm Snapdragon 765G 5G mobile platform which enables improved CPU speeds, 10% faster graphics rendering and delivers peak gaming performance. In other words, Nord is a fast phone. Dragon fast. OnePlus Nord Pretty much everything you could ask for","Rating":"4.1 out of 5 stars","Size":"8GB RAM + 128GB Storage","Color":"Gray Onyx"}]