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
# Load reviews dataframe
df_reviews = pd.read_csv('data/airbnb_last_review.tsv', sep='\t', parse_dates=['last_review'])
df_reviews.head()
df_reviews.info()
# Load price dataframe
df_price = pd.read_csv('data/airbnb_price.csv')
df_price.head()
df_price['price'] = df_price['price'].str.replace('dollars', '').str.strip()
df_price['price'] = df_price['price'].astype('float')
df_price.info()
df_price.head()
# Load room type dataframe
df_rooms = pd.read_excel('data/airbnb_room_type.xlsx')
df_rooms.head()
df_rooms['room_type'].unique()
df_rooms['room_type'] = df_rooms['room_type'].str.lower()
df_rooms['room_type'].unique()
df_rooms['room_type'] = df_rooms['room_type'].astype('category')
df_rooms.info()
# merge data
df = df_reviews.merge(df_price, on="listing_id")
df = df.merge(df_rooms, on="listing_id")
df.head()
df.info()
# What are the dates of the earliest and most recent reviews?
earliest_review = df['last_review'].min()
most_recent = df['last_review'].max()
f'Earliest: {earliest_review}', f'Most Recent: {most_recent}'
# How many of the listings are private rooms?
private_room_count = df[df['room_type'] == 'private room'].shape[0]
private_room_count