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, 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 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
# Import necessary packages
import pandas as pd
import numpy as np
import pandas as pd

# Import all data with filenames
filename_price = 'data/airbnb_price.csv'
filename_lastreview = 'data/airbnb_last_review.tsv'
filename_roomtype = 'data/airbnb_room_type.xlsx'

# Data file to dataframe
price_df = pd.read_csv(filename_price)
lastreview_df = pd.read_csv(filename_lastreview, sep='\t')
roomtype_df = pd.read_excel(filename_roomtype)
# Merge tables on listing_id
airbnb_master = pd.merge(price_df, lastreview_df, on='listing_id')
airbnb_master = pd.merge(airbnb_master, roomtype_df, on='listing_id')
# View a snip of the new total columns
airbnb_master['last_review'] = pd.to_datetime(airbnb_master['last_review']).dt.date
airbnb_master[['price','currency']] = airbnb_master['price'].str.split(' ', expand=True)
airbnb_master['price'] = airbnb_master['price'].str.strip().astype(int)

display(airbnb_master.head(), airbnb_master.dtypes)
# Earliest and most recent review
earliest_review = airbnb_master['last_review'].min()
latest_review = airbnb_master['last_review'].max()

# Number of private room listings
private_rooms = len(airbnb_master[airbnb_master['room_type'].str.lower() == 'private room'])

# Average listing price
average_price = round(airbnb_master['price'].mean(), 2)

# New Dataframe
review_dates = pd.DataFrame({'first_reviewed': [earliest_review], 'last_reviewed': [latest_review], 'nb_private_rooms': [private_rooms], 'avg_price': [average_price]})

print(review_dates)