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, we will take a closer look at the New York Airbnb market by combining data from multiple file types like .csv
, .tsv
, and .xlsx
.
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
# Import necessary packages
import pandas as pd
import numpy as np
# Import CSV
df_price = pd.read_csv("data/airbnb_price.csv")
# Import Excel
df_room_type = pd.read_excel("data/airbnb_room_type.xlsx")
# Import TSV
df_review = pd.read_csv("data/airbnb_last_review.tsv", sep="\t")
# Merging the three DataFrames
airbnb_merged = df_price.merge(df_room_type, on="listing_id").merge(df_review, on="listing_id")
# What are the dates of the earliest and most recent reviews?
airbnb_merged["last_review"] = pd.to_datetime(airbnb_merged["last_review"], format='%B %d %Y')
first_reviewed = airbnb_merged["last_review"].min()
last_reviewed = airbnb_merged["last_review"].max()
# How many of the listings are private rooms?
airbnb_merged['room_type'] = airbnb_merged['room_type'].str.lower().astype("category")
nb_private_rooms = (airbnb_merged["room_type"] == "private room").sum()
# What is the average listing price?
airbnb_merged["price"] = airbnb_merged["price"].str.replace(" dollars", "", regex=False).astype(float)
avg_price = round(airbnb_merged["price"].mean(), 2)
review_dates = pd.DataFrame({
"first_reviewed": [first_reviewed],
"last_reviewed": [last_reviewed],
"nb_private_rooms": [nb_private_rooms],
"avg_price": [avg_price]
})
# Change the Data Type to reduce the data size
airbnb_merged['host_name'] = airbnb_merged['host_name'].astype("category")
airbnb_merged['nbhood_full'] = airbnb_merged['nbhood_full'].astype("category")
airbnb_merged["listing_id"] = airbnb_merged["listing_id"].astype("int32")
airbnb_merged["price"] = airbnb_merged["price"].astype("float32")
print(review_dates)