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

# Begin coding here ...
# Use as many cells as you like
xlsx_df = pd.read_excel('data/airbnb_room_type.xlsx')
csv_df = pd.read_csv('data/airbnb_price.csv', delimiter=',')
tsv_df = pd.read_csv('data/airbnb_last_review.tsv', delimiter='\t')
#merging n dataframe toghether using a common column
merged_df = xlsx_df.merge(csv_df, how='left', left_on='listing_id', right_on='listing_id').merge(tsv_df, how='left', left_on='listing_id', right_on='listing_id')
#recent & oldest review
merged_df['last_review'] = pd.to_datetime(merged_df['last_review'])
earliest_review = merged_df['last_review'].min()
latest_review = merged_df['last_review'].max()
#room type
merged_df['room_type'] = merged_df['room_type'].str.lower()
priv_room = merged_df[merged_df['room_type']=='private room'].shape[0]
#avarage listing price
merged_df['price'] = merged_df['price'].str.replace(' dollars', '')
merged_df['price'] = merged_df['price'].astype(float)
avg_p = merged_df['price'].mean().round(2)
#creating DF with solution
review_dates = pd.DataFrame({
    'first_reviewed' : [earliest_review],
    'last_reviewed' : [latest_review],
    'nb_private_rooms' : [priv_room],
    'avg_price' : [avg_p]
}, index=[0])
review_dates.head()
merged_df.head()