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 ...airbnb_price <- read_csv("data/airbnb_price.csv")
airbnb_price$price <- airbnb_price$price %>%
str_remove_all(fixed(" dollars"))
airbnb_price$price <- as.numeric(airbnb_price$price)
airbnb_price$listing_id <- as.character(airbnb_price$listing_id)
head(airbnb_price)
airbnb_room_type <- read_xlsx("data/airbnb_room_type.xlsx")
airbnb_room_type$listing_id <- as.character(airbnb_room_type$listing_id)
head(airbnb_room_type)airbnb_last_review <- read_tsv("data/airbnb_last_review.tsv")
airbnb_last_review$listing_id <- as.character(airbnb_last_review$listing_id)
library(lubridate)
airbnb_last_review$last_review <- parse_date_time(airbnb_last_review$last_review, orders = c("mdy"))
head(airbnb_last_review)
str(airbnb_last_review)#Join all dataframes
all_data <- airbnb_price %>%
left_join(airbnb_room_type, by = "listing_id") %>%
left_join(airbnb_last_review, by = "listing_id")
head(all_data)nb_private_rooms <- all_data %>%
mutate(lower_rt = tolower(room_type)) %>%
filter(lower_rt == "private room") %>%
count(lower_rt) %>%
pull(n)
review_dates <- all_data %>%
summarise(first_reviewed = min(last_review), last_reviewed = max(last_review), nb_private_rooms = nb_private_rooms, avg_price = round(mean(price), 2))
review_dates