-
Notifications
You must be signed in to change notification settings - Fork 0
/
p08.py
58 lines (41 loc) · 1.35 KB
/
p08.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import quandl
import pandas as pd
import pickle
import matplotlib.pyplot as plt
from matplotlib import style
style.use('fivethirtyeight')
api_key = "Cxe41MDVyJhXQYGuVGx7"
def state_list():
fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
return fiddy_states[0][0][1:]
def grab_initial_state_dat():
states = state_list()
main_df = pd.DataFrame()
for abbv in states:
query = ("FMAC/HPI_" + str(abbv))
df = quandl.get(query, authtoken=api_key)
df.columns = [str(abbv)]
df[abbv] = (df[abbv] - df[abbv][0]) / df[abbv][0] * 100.0
if main_df.empty:
main_df = df
else:
main_df = main_df.join(df)
# print(main_df.head())
pickle_out = open('fiddy_states.pickle', 'wb')
pickle.dump(main_df, pickle_out)
pickle_out.close()
def HPI_benchmark():
df = quandl.get("FMAC/HPI_USA", authtoken=api_key)
df['Value'] = (df['Value'] - df['Value'][0]) / df['Value'][0] * 100.0
return df
# grab_initial_state_dat()
fig = plt.figure()
ax1 = plt.subplot2grid((1, 1), (0, 0))
HPI_data = pd.read_pickle('fiddy_states.pickle')
HPI_data['TX1yr'] = HPI_data['TX'].resample("A").mean()
print(HPI_data[['TX', 'TX1yr']])
HPI_data.dropna(inplace=True)
print(HPI_data[['TX', 'TX1yr']])
HPI_data[['TX', 'TX1yr']].plot(ax=ax1)
plt.legend()
plt.show()