-
Geographical Analysis 6
-
Lecture1.1
-
Lecture1.2
-
Lecture1.3
-
Lecture1.4
-
Lecture1.5
-
Lecture1.6
-
-
Cap Table 3
-
Lecture2.1
-
Lecture2.2
-
Lecture2.3
-
-
Simulation 6
-
Lecture3.1
-
Lecture3.2
-
Lecture3.3
-
Lecture3.4
-
Lecture3.5
-
Lecture3.6
-
-
Search Index 8
-
Lecture4.1
-
Lecture4.2
-
Lecture4.3
-
Lecture4.4
-
Lecture4.5
-
Lecture4.6
-
Lecture4.7
-
Lecture4.8
-
-
Fund Distributions 5
-
Lecture5.1
-
Lecture5.2
-
Lecture5.3
-
Lecture5.4
-
Lecture5.5
-
Airbnb Data
Zooming in on Airbnb¶
To get a clearer picture of the trend and seasonality of airbnb, we will first observe its last 6 years. Indexing to the all dates including and after 1/1/2015 and resting the end is the first task to do.
In [9]:
#Get our sample data
airbnb = df.loc['2015-01-01':]['Airbnb'].reset_index()
airbnb.columns = ['Date', 'Search']
print(airbnb)
Date Search
0 2015-01-01 20.0
1 2015-02-01 22.0
2 2015-03-01 23.0
3 2015-04-01 28.0
4 2015-05-01 34.0
.. ... ...
67 2020-08-01 90.0
68 2020-09-01 73.0
69 2020-10-01 62.0
70 2020-11-01 53.0
71 2020-12-01 95.0
[72 rows x 2 columns]
For columns of the datetime type, we can use dt followed by a part of the date we want to return things like the year for each date, the month of each date, etc.
In [10]:
airbnb['Year'] = airbnb['Date'].dt.year
airbnb['Month'] = airbnb['Date'].dt.month
print(airbnb)
Date Search Year Month
0 2015-01-01 20.0 2015 1
1 2015-02-01 22.0 2015 2
2 2015-03-01 23.0 2015 3
3 2015-04-01 28.0 2015 4
4 2015-05-01 34.0 2015 5
.. ... ... ... ...
67 2020-08-01 90.0 2020 8
68 2020-09-01 73.0 2020 9
69 2020-10-01 62.0 2020 10
70 2020-11-01 53.0 2020 11
71 2020-12-01 95.0 2020 12
[72 rows x 4 columns]
In [11]:
#Pivot the date by month and year
airbnb = airbnb.pivot('Month', 'Year', 'Search')
print(airbnb)
Year 2015 2016 2017 2018 2019 2020
Month
1 20.0 34.0 51.0 66.0 72.0 84.0
2 22.0 36.0 54.0 65.0 70.0 82.0
3 23.0 38.0 59.0 71.0 75.0 60.0
4 28.0 39.0 60.0 66.0 73.0 36.0
5 34.0 49.0 62.0 69.0 80.0 72.0
6 37.0 58.0 68.0 79.0 93.0 100.0
7 38.0 50.0 72.0 81.0 92.0 96.0
8 38.0 46.0 65.0 70.0 83.0 90.0
9 31.0 40.0 54.0 60.0 72.0 73.0
10 30.0 39.0 52.0 55.0 69.0 62.0
11 28.0 39.0 50.0 51.0 64.0 53.0
12 30.0 38.0 49.0 54.0 64.0 95.0
In [12]:
#Plot the data
ax = airbnb.plot(kind='line')
ax.set_xlabel("Month")
ax.set_ylabel("Search Index")
ax.set_title("Google Search Index Airbnb Yearly Comparison")
plt.show()
Prev
Search index
Next
Prediction