import pandas as pd
import quandl as ql
import matplotlib as plt
% matplotlib inline
api_key=open('api_key.txt').read()
df=ql.get('FMAC/HPI_AK', authtoken=api_key)
df.plot()
us_states=pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
for abbv in us_states[0][1][1:]:
print('FMAC/HPI_' + str(abbv))
for abbv in us_states[0][1][1:]:
query = "FMAC/HPI_"+str(abbv)
df = ql.get(query, authtoken=api_key)
df.rename(columns={'Value':str(abbv)} , inplace=True)
df.plot()
def fifty_states():
fifty_states=pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')
return fifty_states[0][1][1:]
def get_initial_state_data():
states=fifty_states()
main_df = pd.DataFrame()
for abbv in states:
query = "FMAC/HPI_"+str(abbv)
df=quandl.get(query, authtoken=api_key)
df.rename(columns={'Value':str(abbv)} , inplace=True)
if main_df.empty:
main_df=df
else:
main_df = main_df.join(df)
main_df.plot()
save_file=open('fifty_states.pickle','wb')
pickle.dump(main_df,save_file)
save_file.close()
import pickle
# using pickle of python
saved_file=open('fifty_states.pickle','rb')
HPI_data=pickle.load(saved_file)
HPI_data.plot(legend=None)
#using pickle for pandas
HPI_data.to_pickle('fifty_states_pandas.pickle')
HPI_data2=pd.read_pickle('fifty_states_pandas.pickle')
HPI_data2.head()
from matplotlib import style
style.use('ggplot')
def get_initial_state_data():
states = fifty_states()
main_df = c
for abbv in states:
query = "FMAC/HPI_"+str(abbv)
df = quandl.get(query, authtoken=api_key)
df.rename(columns = {'Value': str(abbv)}, inplace=True)
df = df.pct_change()
if main_df.empty:
main_df = df
else:
main_df = main_df.join(df)
main_df.plot()
save_file = open('fifty_states_pct_change.pickle', 'wb')
pickle.dump(main_df, save_file)
save_file.close()
HPI_data = pd.read_pickle('fifty_states_pct_change.pickle')
HPI_data.plot(legend=None)
def get_initial_state_data():
states=fifty_states()
main_df = pd.DataFrame()
for abbv in states:
query = "FMAC/HPI_"+str(abbv)
df = quandl.get(query, authtoken=api_key)
df.rename(columns={'Value':str(abbv)} , inplace=True)
df[abbv]=(df[abbv]-df[abbv][0])/df[abbv][0]*100
if main_df.empty:
main_df = df
else:
main_df = main_df.join(df)
main_df.plot()
save_file=open('fifty_states_pct_change_5.pickle','wb')
pickle.dump(main_df,save_file)
save_file.close()
HPI_data=pd.read_pickle('fifty_states_pct_change_5.pickle')
HPI_data.plot(legend=None)