Workspace
Khumbo Ziba/

Project: Exploring Airbnb Market Trends

0
Beta
Spinner

Project Real Estate

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 ...

#Importing the airbnb_price csv data
path_csv = "data/airbnb_price.csv"
price = read_csv(path_csv, col_names = TRUE,
                 col_types = NULL)

#import the airbnb_room_type.xlsx data
path_xlsx = "data/airbnb_room_type.xlsx"
room_type = read_excel(path_xlsx,
                       sheet = 1)

# Import the airbnb_last_review.tsv data
path_tsv = "data/airbnb_last_review.tsv"
last_review = read_tsv(path_tsv, col_names = TRUE,
                       col_types = NULL)
# Loading the necessary packages tidyr,dplyr,assertive.base, stringr
library(dplyr)
library(tidyr)
library(assertive.base)
library(stringr)

# Inspect the extracted data
glimpse(price)
glimpse(last_review)
glimpse(room_type)

#Join the three data sets
ny_estate = price %>%
	inner_join(last_review, by = "listing_id") %>%
	inner_join(room_type, by = "listing_id")

#Check the structure of the joined dataset ny_estate
str(ny_estate)
ny_estate
#Data cleaning

#Loading the necessary packages
library(assertive.base)
library(lubridate)
library(dplyr)
library(tidyr)
library(stringr)
library(tools)

#Cleaning column types in the ny_estate data frame to their appropriate types
# Assuming the date format in 'last_review' column is 'month/day/year' and all other columns are character columns
ny_estate_type = ny_estate %>%
	mutate(last_review = as.Date(as.character(last_review), format = "%B %d %Y"),
		   listing_id = as.numeric(as.character(listing_id)),
		   room_type = tolower(room_type)) %>%
	separate(price, into = c("price", "unit"), sep = " ") %>%
	mutate(price = as.numeric(as.character(price)))
summary(ny_estate_type)

#Cleaning the price variable to remove all observations with a zero(0) price
ny_estate_clean = ny_estate_type %>%
	subset(price != 0)
ny_estate_clean

#Determining the earliest and most recent review dates

review_dates = ny_estate_type %>%
	summarize(first_reviewed = min(last_review),
			 last_reviewed = max(last_review),
			 nb_private_rooms = sum(room_type == "private room"),
			  avg_price = mean(price))

print(review_dates)
  • AI Chat
  • Code