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_last_review= pd.read_csv('data/airbnb_last_review.tsv', sep='\t')
# Convert the review_date column to datetime format
airbnb_last_review['last_review'] = pd.to_datetime(airbnb_last_review['last_review'], format='%B %d %Y', errors='coerce')
airbnb_last_review.info()
# Find the earliest and latest review dates
earliest_review_date = airbnb_last_review['last_review'].min()
latest_review_date = airbnb_last_review['last_review'].max()
# Print the results
print(f"\nEarliest review date: {earliest_review_date}")
print(f"Most recent review date: {latest_review_date}")
airbnb_room_type= pd.read_excel('data/airbnb_room_type.xlsx')
airbnb_room_type['room_type']=airbnb_room_type['room_type'].str.lower()
# Count the entries where room_type is "private room"
private_room_count = airbnb_room_type['room_type'].value_counts().get('private room', 0)
airbnb_price=pd.read_csv('data/airbnb_price.csv')
airbnb_price['price'] = airbnb_price['price'].str.replace('dollars', '', regex=False)
# Remove the word 'dollars' and strip any leading or trailing whitespace
airbnb_price['price'] = airbnb_price['price'].str.replace('dollars', '', regex=False).str.strip()
# Convert the cleaned listing_price column to numeric format
airbnb_price['price'] = pd.to_numeric(airbnb_price['price'] , errors='coerce')
average_price = airbnb_price['price'].mean()
# Round to two decimal places
avg_price = round(average_price, 2)
# Create a DataFrame with one row
review_dates = pd.DataFrame({
'first_reviewed': [earliest_review_date],
'last_reviewed': [latest_review_date],
'nb_private_rooms': [private_room_count],
'avg_price': [avg_price]
})
print(review_dates)