Skip to content

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 listing
  • price: nightly listing price in USD
  • nbhood_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 listing
  • description: listing description
  • room_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 listing
  • host_name: name of listing host
  • last_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 ...
# Import the data
price <- read_csv("data/airbnb_price.csv", show_col_types = FALSE)
room_type <- read_excel("data/airbnb_room_type.xlsx")
review <- read_tsv("data/airbnb_last_review.tsv", show_col_types = FALSE)
# Combine the data
airbnb <- price %>%
	inner_join(room_type, by = "listing_id") %>%
	inner_join(review, by = "listing_id")
# Review the data
head(airbnb)
unique(airbnb$room_type)
# Convert to date time

airbnb$last_review <- as.Date(airbnb$last_review, format = "%b %d %Y")

# Date of the earliest reviews
first_reviewed <- airbnb %>%
	summarize(min(last_review))



# Date of most recent review
last_reviewed <- airbnb %>%
	summarize(max(last_review))
# Find the number of private rooms
nb_private_rooms <- airbnb %>%
  summarize(nb_private_rooms = sum(room_type %in% c("private room", "Private room", "PRIVATE ROOM")))
nb_private_rooms
# Cleaning price column
airbnb <- airbnb %>%
	mutate(price = as.numeric(str_remove(price, "dollars")))
# Review the changes
head(airbnb)
# Find the average listing price for all rooms rounded to the nearest penny
avg_price <- airbnb %>%
	summarize(round(mean(price), 2))

avg_price
# Assuming the variables first_review, last_reviewed, nb_private_rooms, and avg_price are defined
# Create data frame with all values
review_dates <- data.frame(
  first_reviewed = first_reviewed, 
  last_reviewed = last_reviewed, 
  nb_private_rooms = nb_private_rooms, 
  avg_price = avg_price
)
# View new data frame
review_dates