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 pandas as pd
import numpy as np
from functools import reduce

# Prices.
airbnb_price = pd.read_csv('data/airbnb_price.csv')

# Room types.
airbnb_room_type = pd.read_excel('data/airbnb_room_type.xlsx')

# Review dates.
airbnb_last_review = pd.read_csv('data/airbnb_last_review.tsv', sep='\t', 
                                 parse_dates=['last_review'], date_parser=lambda x: pd.to_datetime(x, format='%B %d %Y'))

# One DataFrame from three.
dfs = [airbnb_price, airbnb_room_type, airbnb_last_review]
listings = reduce(lambda left, right: pd.merge(left, right, on='listing_id'), dfs)
listings.head()
# What are the dates of the earliest and most recent reviews?
first_reviewed = listings['last_review'].min().date()
last_reviewed = listings['last_review'].max().date()
print(f"The earliest review: {first_reviewed}, the most recent review: {last_reviewed}.")
# How many of the listings are private rooms?
print(listings['room_type'].unique())

# Bring relevant data to the same format.
listings['room_type'] = listings['room_type'].str.lower()
private_room_count = listings[listings['room_type'] == 'private room'].shape[0]
print(f"Number of listed private room: {private_room_count}.")

# What is the average listing price?
# print(listings['price'].unique())

# Remove " dollars" from each value.
listings['price_clean'] = listings['price'].str.replace(' dollars', '').astype(float)
avg_price = listings['price_clean'].mean()

print(f"The average listing price is ${avg_price:.2f}.")