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
 # Load price dataset
airbnb_price = pd.read_csv('data/airbnb_price.csv')
airbnb_price.head(2)
# Load rooms dataset
airbnb_rooms = pd.read_excel('data/airbnb_room_type.xlsx')
airbnb_rooms.head(2)
# Load reviews dataset
airbnb_revs = pd.read_csv('data/airbnb_last_review.tsv', sep='tabs')
airbnb_revs.head(2)
1. What are the dates of the earliest and most recent reviews?
airbnb_revs.columns
airbnb_revs['last_review'] = airbnb_revs['listing_id\thost_name\tlast_review'].apply(
    lambda rev_str: pd.to_datetime(str(rev_str).split('\t')[2]))
Hidden output
first_reviewed = airbnb_revs['last_review'].min()
last_reviewed = airbnb_revs['last_review'].max()
2. How many of the listings are private rooms?
airbnb_rooms['room_type'].unique()
pri_rooms = ['private room', 'Private room', 'PRIVATE ROOM']
nb_private_rooms = len(airbnb_rooms.query('room_type in @pri_rooms'))
3. What is the average listing price?
airbnb_price.columns
avg_price = round(airbnb_price['price'].str.extract(r'(\d+)').astype('float').mean(), 2)