pandas_joiningData.py 827 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import pickle
  2. import pandas as pd
  3. import quandl
  4. import matplotlib.pyplot as plt
  5. from matplotlib import style
  6. style.use('seaborn')
  7. quandl.ApiConfig.api_key = 'rFsSehe51RLzREtYhLfo'
  8. def mortgage_30yr():
  9. df = quandl.get('FMAC/MORTG')
  10. df = df[df.index > "1974-12-01"]
  11. df = (df['Value'] - df['Value'][0]) / df['Value'][0] * 100
  12. df = df.resample('M').mean()
  13. return df
  14. ax1 = plt.subplot(2,1,1)
  15. ax2 = plt.subplot(2,1,2, sharex=ax1)
  16. # initial_state_data()
  17. pickle_in = open('fifty_states_pct.pickle' , 'rb')
  18. HPI_data = pickle.load(pickle_in)
  19. # HPI_Benchmark()
  20. pickle_in = open('us_pct.pickle','rb')
  21. benchmark = pickle.load(pickle_in)
  22. m30 = mortgage_30yr()
  23. HPI_Bench = benchmark
  24. state_HPI_M30 = HPI_data.join(m30)
  25. state_HPI_M30.rename({'Value' : 'M30'}, inplace=True)
  26. print(state_HPI_M30.corr().describe()['Value'])