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
# Begin coding here ...
# Use as many cells as you like
price = pd.read_csv("data/airbnb_price.csv")
room_type = pd.read_excel('data/airbnb_room_type.xlsx', sheet_name='airbnb_room_type', header=0, index_col=0)
last_review = pd.read_csv("data/airbnb_last_review.tsv", sep='\t')
data = pd.merge(price, room_type, on="listing_id", how="inner")
final_merged_df = pd.merge(data, last_review, on="listing_id", how="inner")
final_merged_df.head()
final_merged_df.info()
final_merged_df["room_type"] = final_merged_df["room_type"].str.lower()
final_merged_df["nbhood_full"] = final_merged_df["nbhood_full"].str.lower()
final_merged_df["price"] = final_merged_df["price"].str.strip("dollars")
final_merged_df["price"] = final_merged_df["price"].astype("int")
final_merged_df["last_review"] = pd.to_datetime(final_merged_df["last_review"])
most_recent_review = final_merged_df["last_review"].max()
most_early_review = final_merged_df["last_review"].min()
print(final_merged_df["room_type"].value_counts())
private_rooms_cnt = 11356
print(round(final_merged_df["price"].mean(),2))
avg_listing_price = 141.78
aggregated_data = {
"first_reviewed": [most_early_review],
"last_reviewed": [most_recent_review],
"nb_private_rooms": [private_rooms_cnt],
"avg_price": [avg_listing_price]
}
review_dates = pd.DataFrame(aggregated_data)
review_dates.head()