Welcome to New York City, one of the most-visited cities in the world. There are many Airbnb listings in New York City to meet the high demand for temporary lodging for travelers, which can be anywhere between a few nights to many months. In this project, you will take a closer look at the New York Airbnb market by combining data from multiple file types like .csv, .tsv, and .xlsx (Excel files).
Recall that CSV, TSV, and Excel files are three common formats for storing data. Three files containing data on 2019 Airbnb listings are available to you:
data/airbnb_price.csv This is a CSV file containing data on Airbnb listing prices and locations.
listing_id: unique identifier of listingprice: nightly listing price in USDnbhood_full: name of borough and neighborhood where listing is located
data/airbnb_room_type.xlsx This is an Excel file containing data on Airbnb listing descriptions and room types.
listing_id: unique identifier of listingdescription: listing descriptionroom_type: Airbnb has three types of rooms: shared rooms, private rooms, and entire homes/apartments
data/airbnb_last_review.tsv This is a TSV file containing data on Airbnb host names and review dates.
listing_id: unique identifier of listinghost_name: name of listing hostlast_review: date when the listing was last reviewed
# We've loaded the necessary packages for you in the first cell. Please feel free to add as many cells as you like!
suppressMessages(library(dplyr)) # This line is required to check your answer correctly
options(readr.show_types = FALSE) # This line is required to check your answer correctly
library(readr)
library(readxl)
library(stringr)
# Begin coding here ...
price <- read_csv("data/airbnb_price.csv")
room_type <- read_excel("data/airbnb_room_type.xlsx")
last_review <- read_tsv("data/airbnb_last_review.tsv")
# joining all the dataframes together
listings <- airbnb_price %>%
inner_join(airbnb_room_type, by="listing_id") %>%
inner_join(airbnb_last_review, by="listing_id")
head(listings, 5)
# Question 1: When were the earliest and most recent reviews in the dataset?
# we need to first convert the date into datetime type
listings = listings %>%
mutate(last_review_date = as.Date(last_review, format= "%B %d %Y"))
# getting the required dates
review_dates <- listings %>%
summarise(first_reviewed = min(last_review_date),
last_reviewed = max(last_review_date))
review_dates
# Question 2: How many of the listings are private rooms?
# getting the frequency of the room_tye category
listings %>%
count(room_type)
# Here, the categories contain same name with different cases
# converting them to a standard lower case types
listings = listings %>%
mutate(room_type = str_to_lower(room_type))
# again getting the frequency
listings %>%
count(room_type)
# getting the total number of private rooms
private_room_count <- listings %>%
count(room_type) %>%
filter(room_type == "private room")
nb_private_rooms <- private_room_count$n
nb_private_rooms
# Question 3: What is the average listing price?
# checking the data type of the dataframe
glimpse(listings)
# we need to change the data tpe of price from string to numeric
listings = listings %>%
mutate(price = str_remove(price, " dollars") %>%
as.numeric())
glimpse(listings)
# calculating the average listing price
avg_price <- listings %>%
summarize(avg_price = mean(price)) %>%
as.numeric()
avg_pricereview_dates <- listings %>%
summarize(first_reviewed = min(last_review_date),
last_reviewed = max(last_review_date),nb_private_rooms,avg_price)
review_dates