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
# We've loaded your first package for you! You can add as many cells as you need.
import numpy as np

# Begin coding here ...

1 - Loading the data

import pandas as pd
# Using pandas methods to read files
# Read csv file
df_price = pd.read_csv('data/airbnb_price.csv')
# Read tsv file
df_review = pd.read_csv('data/airbnb_last_review.tsv', sep = '\t')
# Read excel file
df_room = pd.read_excel('data/airbnb_room_type.xlsx')
# Looking at the data
print(df_price.head())
print(df_review.head())
print(df_room.head())

2 - Merging the three DataFrames

# Merging two DataFrames at a time on a common column
df_merge = df_price.merge(df_review, on = 'listing_id').merge(df_room, on = 'listing_id')
print(df_merge.head())
print(df_merge.info())
print(df_merge.shape)

3 - Determing the earliest and most recent review dates

# Converting reviews data to date format
df_merge['last_review'] = pd.to_datetime(df_merge['last_review'], format = '%B %d %Y')
print(df_merge['last_review'].head())
# Finding the earliest and most recent review dates
first_reviewed = df_merge['last_review'].min()
last_reviewed = df_merge['last_review'].max()
print(first_reviewed)
print(last_reviewed)

4 - Finding how many listings are private rooms

# Issues with capitalization
print(df_merge['room_type'].value_counts())
# Cleaning data with pandas
df_merge['room_type'] = df_merge['room_type'].str.lower()
print(df_merge['room_type'].value_counts())
# Counting the number of private rooms
nb_private_rooms = df_merge[df_merge['room_type'] == 'private room'].shape[0]
print(nb_private_rooms)

5 - Finding the average price of listings