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
import datetime

# Begin coding here ...
# Use as many cells as you like
# Import or load data
df_price = pd.read_csv('data/airbnb_price.csv')

# View the header
df_price.head()
# Load the excel file sheets
df_room_type_sheets = pd.ExcelFile('data/airbnb_room_type.xlsx')

# View how many sheets in the file
df_room_type_sheets.sheet_names
# Parse the first sheet to DataFrame
df_room_type = df_room_type_sheets.parse(0)

# View the DataFrame header
df_room_type.head()
# Import or load data from the .tsv file
df_review = pd.read_table('data/airbnb_last_review.tsv', delimiter= '\t')

# View the header
df_review.head()
df_price.info()
df_room_type.info()
df_review.info()
# Check if the 3 DataFrames have a common column
(df_price.loc[:, 'listing_id'] == df_review.loc[:, 'listing_id']).sum(), (df_price.loc[:, 'listing_id'] == df_room_type.loc[:, 'listing_id']).sum()
# Join the 3 DataFrames since they have a common unique identifier column 
inner_join_df = pd.merge(df_price, df_room_type, on='listing_id', how='inner')
inner_join_df = pd.merge(inner_join_df, df_review, on='listing_id', how='inner')
inner_join_df.head()
# Information of the new joined DataFrame
inner_join_df.info()
inner_join_df['price'].head()
# Remove the word 'dollars' from price column and convert to integer data type
inner_join_df['price'] = inner_join_df['price'].str.strip('dollars').astype('int')
inner_join_df['price'].info()
# Check how many unique values present
inner_join_df['room_type'].nunique()