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

airbnb_price = pd.read_csv('data/airbnb_price.csv')
airbnb_room_type = pd.read_excel('data/airbnb_room_type.xlsx')
airbnb_last_review = pd.read_csv('data/airbnb_last_review.tsv', delimiter='\t')
print("Airbnb Price \n", airbnb_price.head())
print("Airbnb Room Type \n", airbnb_room_type.head())
print("Airbnb Last Review \n", airbnb_last_review.head())

Merging the three datasets

df_1 = airbnb_price.merge(airbnb_room_type, on='listing_id')
df = df_1.merge(airbnb_last_review, on='listing_id')
df.head()

Finding the earliest and most recent review dates

df['last_review'] = pd.to_datetime(df['last_review'], format='%B %d %Y')
print(f"The earliest and moste recent review dates are {df['last_review'].min()} and {df['last_review'].max()}, respectively.")
first_reviewed = df['last_review'].min()
last_reviewed = df['last_review'].max()
df.info()

Number of listings of private rooms

df['room_type'] = df['room_type'].str.lower()
print(f"The number of listed private rooms is {df[df['room_type'] == 'private room'].shape[0]}.")
nb_private_rooms = df[df['room_type'] == 'private room'].shape[0]

Average Price of listings

df['price'] = df['price'].str.replace(' dollars', '').astype('int32')
print(f"The average price of listings is {round(df['price'].mean(), 2)}.")
avg_price = df['price'].mean()

Summary

review_dates = pd.DataFrame(
    {'first_reviewed': [first_reviewed], 
    'last_reviewed': [last_reviewed],
    'nb_private_rooms': [nb_private_rooms],
    'avg_price': [round(avg_price, 2)]}
)
review_dates