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
# Begin coding here ...
# Use as many cells as you like
airbnb_csv_df = pd.read_csv('data/airbnb_price.csv')
# airbnb_csv_df.head(5)
airbnb_tsv_df = pd.read_csv('data/airbnb_last_review.tsv', sep='\t')
# airbnb_tsv_df.head(5)
airbnb_xls_df = pd.read_excel('data/airbnb_room_type.xlsx')
# airbnb_xls_df.head(5)
airbnb_merged_df = pd.merge(airbnb_csv_df, airbnb_tsv_df, on='listing_id')
airbnb_merged_sec_df = pd.merge(airbnb_merged_df, airbnb_xls_df, on='listing_id')
airbnb_merged_sec_df.head(10)#converts to datetime format
airbnb_merged_sec_df['last_review'] = pd.to_datetime(airbnb_merged_sec_df['last_review'], format='%B %d %Y')
#earliest review dates
earliest_date = airbnb_merged_sec_df['last_review'].min()
earliest_date
# most recent review dates
recent_review = airbnb_merged_sec_df['last_review'].max()
recent_review
#private rooms
#convert to lower case
airbnb_merged_sec_df['room_type'] = airbnb_merged_sec_df['room_type'].str.lower()
private_rooms = airbnb_merged_sec_df[airbnb_merged_sec_df['room_type'] == 'private room' ].shape[0]
private_rooms
#average price of listings
#convert price to number, removing the dollar from each value
airbnb_merged_sec_df['price_clean'] = airbnb_merged_sec_df['price'].str.replace(' dollars', '').astype(float)
average_price_listings = airbnb_merged_sec_df['price_clean'].mean()
average_price_listings
#dataFrame with 4 solution values
review_dates = pd.DataFrame({
'first_reviewed' : [earliest_date],
'last_reviewed' : [recent_review],
'nb_private_rooms' : [private_rooms],
'avg_price' : [average_price_listings]
})
print(review_dates)