Visualizing Airbnb Price
To visualizing the change of Airbnb in my project, I started with analyzing the attributes in the Airbnb data list. As I could not find the reservation data for each apartment, I used the price and number of reviews to see if there is any interesting information. In the above GIF, it seems like the most expensive Airbnb does not have the highest number reviews. Those with lower price received more reviews.
In this exercise, I downloaded the Airbnb listing of September, 2017 and chose Harlem, Manhattan as an example of the neighborhood. I cleaned the rows that had empty data, had 0 reviews, 0 available days, and were last reviewed before 2017/7 . There were finally 99 rows of Harlem Airbnb listing in the new Google sheet. The next step coding is :
import csv
def setup():
size(1500, 1000)
with open("airbnb20170902clean.csv") as f:
reader = csv.reader(f)
header = reader.next() # Skip the header row
#define new names for variables in the new list
global ids
ids = []
global neighborhoods
neighborhoods = []
global latitudes
latitudes = []
global longitudes
longitudes = []
global prices
prices = []
global reviews
reviews = []
for row in reader:
id = row[0]
ids.append(id)
neighborhood = row[5]
neighborhoods.append(neighborhood)
price = int(row[9])
prices.append(price)
number_of_reviews = int(row[11])
reviews.append(number_of_reviews)
def draw():
background(0)
scalar =20
x = 2
y = 2
#this is the text
fill(255)
textSize(50)
text("Harlem, New York", 100, 200)
textSize(30)
text("The price of airbnb is $", 100, 800)
fill(180)
text("This airbnb is reviewed by times", 100, 850)
#this is how the price of each airbnb is presented
for price in prices:
leftEdge = x - (price / scalar) / 1.5
rightEdge = x + (price / scalar) / 1.5
if leftEdge < mouseX and mouseX < rightEdge:
fill(255,0,0)
rect(x, height-400, scalar/1.5, (price/scalar*10)*(-1))
#this is the price for the selected airbnb
textSize(30)
fill(255,0,0)
text(price, 460, 800)
else:
fill(255,255,255) #this is an RGB color
rect(x, height-400, scalar/1.5, (price/scalar*15)*(-1))
x += 15
#this is how the number of reviews according to each airbnb is presented
for number_of_review in reviews:
leftEdge = y - (number_of_review / scalar) / 1.5
rightEdge = y + (number_of_review / scalar) / 1.5
if leftEdge < mouseX and mouseX < rightEdge:
fill(127,0,0)
rect(y, height-400, scalar/1.5, number_of_review/scalar*10)
#this is the reviews for the selected airbnb
textSize(30)
fill(255,0,0)
text(number_of_review, 500, 850)
else:
fill(180,180,180) #this is an RGB color
rect(y, height-400, scalar/1.5, number_of_review/scalar*10)
y += 15
#display the airbnb logo
global img
img = loadImage("Airbnb-new-logo-2014.png")
image(img, 600, -150)
To further use this tutorial in my project, what I could do is to visualize the Airbnb listing data based on neighborhood, and compare the Airbnb reservation data and the crime rate in the same neighborhood. One of the current problem is that I cannot get the reservation data. Maybe I would just use “the number of Airbnb on list” as the variable. And another problem is the data is so huge in one month, and even larger if I want to analyze the data for several years.