### Tutorial 3 Question 1: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.
## Descriptive Question:
# Is there any vaccine out there to prevent Covid-19?
# From which country the Covid-19 disease had spread?
## Exploratory Question:
# Is hand sanitizer effective against Covid-19?
# If I vape tobacco or nicotine am I at risk for complications from COVID-19?
##Inferential Question:
#What can be the maximun death rate for covid-19
#What will be the maximum number of affected covid-19 case?
##Predictive
#What are the country list will be in danger zone after second wave of covid-19?
#Which country will have best recovery among all the country?
### Tutorial 3 Question 2:
library(xml2)
library(rvest)
library(stringr)
library(jsonlite)
webpage<-read_html("https://www.amazon.in/OnePlus-Nord-Marble-128GB-Storage/dp/B086977J3K/ref=sr_1_2?dchild=1&keywords=one+pluse6&qid=1604752409&s=electronics&sr=1-2")
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 (Blue Marble, 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 (Blue Marble, 8GB RAM, 128GB Storage)"
price_html<-html_nodes(webpage, 'span#priceblock_dealprice')
price <- html_text(price_html)
str_replace_all(price, "[\r\n]" , "")
## [1] "<U+20B9> 27,999.00"
head(price)
## [1] "<U+20B9> 27,999.00"
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:Marble BlueNord, 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)
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] "Marble Blue"
product_data <- data.frame(Title = title, Price = price,Description = desc, Rating = rate, Size = size, Color = color)
str(product_data)
## 'data.frame': 1 obs. of 6 variables:
## $ Title : chr "\n\n\n\n\n\n\n\n\nOnePlus Nord 5G (Blue Marble, 8GB RAM, 128GB Storage)\n\n\n\n\n\n\n\n\n\n\n\n\n"
## $ Price : chr "<U+20B9> 27,999.00"
## $ Description: chr "Style name:8GB RAM + 128GB Storage | Colour:Marble BlueNord, the latest product line by the Number 1 premium sm"| __truncated__
## $ Rating : chr "4.1 out of 5 stars"
## $ Size : chr "8GB RAM + 128GB Storage"
## $ Color : chr "Marble Blue"
json_data <- toJSON(product_data)
cat(json_data)
## [{"Title":"\n\n\n\n\n\n\n\n\nOnePlus Nord 5G (Blue Marble, 8GB RAM, 128GB Storage)\n\n\n\n\n\n\n\n\n\n\n\n\n","Price":"<U+20B9> 27,999.00","Description":"Style name:8GB RAM + 128GB Storage | Colour:Marble BlueNord, 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":"Marble Blue"}]