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
# We've loaded your first package for you! You can add as many cells as you need.
import numpy as np
import pandas as pd
# Import data
airbnb_price_df = pd.read_csv('data/airbnb_price.csv')
print(airbnb_price_df.head())
airbnb_room_type_df = pd.read_excel('data/airbnb_room_type.xlsx')
print(airbnb_room_type_df.head())
airbnb_last_review_df = pd.read_csv('data/airbnb_last_review.tsv', sep='\t')
print(airbnb_last_review_df.head())
# Find earliest and most recent reviews in airbnb_last_review_df
airbnb_last_review_df['last_review'] = pd.to_datetime(airbnb_last_review_df['last_review'])
first_reviewed_df = airbnb_last_review_df.sort_values('last_review', ascending=True)
last_reviewed_df = airbnb_last_review_df.sort_values('last_review', ascending=False)
first_reviewed = first_reviewed_df['last_review'].iloc[0]
last_reviewed = last_reviewed_df['last_review'].iloc[0]
print(f"The earliest review was on {first_reviewed_df['last_review'].iloc[0]}.")
print(f"The most recent review has been on {last_reviewed_df['last_review'].iloc[0]}.")
# Find number of private rooms in airbnb_room_type_df
airbnb_room_type_df['room_type'] = airbnb_room_type_df['room_type'].str.lower()
nb_private_rooms = airbnb_room_type_df[airbnb_room_type_df['room_type'] == 'private room']['listing_id'].count()
print(f'There are {nb_private_rooms} private rooms in the list.')
# Find the mean price in airbnb_price_df
airbnb_price_df['dolar_price'] = airbnb_price_df['price'].str.replace('dollars','').astype('int')
avg_price = (airbnb_price_df['dolar_price'].mean().round(2))
print(f'The average listing price is {avg_price} dollars')
# New df with these variables
review_dates = pd.DataFrame({'first_reviewed': [first_reviewed],
'last_reviewed': [last_reviewed],
'nb_private_rooms': [nb_private_rooms],
'avg_price': [avg_price]})
print(review_dates)