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

Necessary Libraries

import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

Importing Raw Data

reviews_data = pd.read_csv('data/airbnb_last_review.tsv', sep='\t')
prices_data = pd.read_csv('data/airbnb_price.csv')
room_type = pd.read_excel('data/airbnb_room_type.xlsx')
print(reviews_data.head())
print(prices_data.head())
print(room_type.head())

Combining raw data into a single DataFrame

price_review = prices_data.merge(reviews_data, on='listing_id', how='left')
airbnb_nyc = price_review.merge(room_type, on='listing_id',how='left')
airbnb_nyc.head()

Datatypes of Each Column

airbnb_nyc.dtypes

Missing Value Check

airbnb_nyc.isna().sum()

Number of Unique Values

airbnb_nyc['listing_id'].nunique()

Feature Engineering

airbnb_nyc['last_review']=pd.to_datetime(airbnb_nyc['last_review']).dt.date
airbnb_nyc['month']=pd.to_datetime(airbnb_nyc['last_review']).dt.month
airbnb_nyc['room_type'] = airbnb_nyc['room_type'].str.lower()
airbnb_nyc['price'] = airbnb_nyc['price'].replace(r'[^\d]','',regex=True).astype(float)
airbnb_nyc[['borough', 'neighborhood']] = airbnb_nyc['nbhood_full'].astype(str).str.split(', ', n=1, expand=True)

airbnb_nyc.head()