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 listingprice: nightly listing price in USDnbhood_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 listingdescription: listing descriptionroom_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 listinghost_name: name of listing hostlast_review: date when the listing was last reviewed
# Import necessary packages
import pandas as pd
import numpy as np
# Read the csv file and check the top 5 records
prices = pd.read_csv('data/airbnb_price.csv')
#print(prices.head())
#Read the xlsx file and check the top 5 recoreds
room_types = pd.read_excel('data/airbnb_room_type.xlsx')
#print(room_types.head())
#Read the tsv file and check the top 5 records
reviews = pd.read_table('data/airbnb_last_review.tsv')
#print(reviews.head())
#Combining the 3 dataframes
prices_room = pd.merge(prices, room_types, on = 'listing_id')
airbnb_listing =pd.merge(prices_room, reviews, on = 'listing_id')
#print(airbnb_listing.info())
#Convert the last_review column to datetime formate
airbnb_listing['last_review'] = pd.to_datetime(airbnb_listing['last_review'], format = '%B %d %Y')
#print(airbnb_listing.info())
#Get the earliest and the most recent date
earliest_date = airbnb_listing['last_review'].min()
recent_date = airbnb_listing['last_review'].max()
#print(earliest_date)
#print(recent_date)
#number of listing rooms that are private
airbnb_listing['room_type'] = airbnb_listing['room_type'].str.lower()
number_of_private_room = (airbnb_listing['room_type'] == 'private room').sum()
#print(number_of_private_room)
#Remove the dollar string from the column
airbnb_listing['price'] = airbnb_listing['price'].str.replace('dollars', '')
#Covert price column to float
airbnb_listing['price'] = airbnb_listing['price'].astype('float')
#Get the average price round to 2 decimal place
average_price = round(airbnb_listing['price'].mean(), 2)
#Combines the variables to a dataframe
review_dates = pd.DataFrame([{
'first_reviewed': earliest_date,
'last_reviewed': recent_date,
'nb_private_rooms': number_of_private_room,
'avg_price': average_price
}])
print(review_dates)