Pandas学习总结(上)
来源:互联网 发布:时间序列数据集 编辑:程序博客网 时间:2024/06/08 06:45
Python科学计算-Pandas(上)
Author:Xie Zhong-zhao
Date: 2017/8/8
Running Environment: Python3.5
1、Pandas Basics - Data Analysis with Python and Pandas Tutorial
import pandas as pdweb_stats = {'Day':[1,2,3,4,5,6], 'Visitors':[43,34,65,56,29,76], 'Bounce Rate':[65,67,78,65,45,52]}df = pd.DataFrame(web_stats)print(df.head())print("\n")print(df.tail())print("\n")print(df.tail(2))print("\n")#df.set_index('Day', inplace=True)df = df.set_index('Day')print(df)
Bounce Rate Day Visitors0 65 1 431 67 2 342 78 3 653 65 4 564 45 5 29 Bounce Rate Day Visitors1 67 2 342 78 3 653 65 4 564 45 5 295 52 6 76 Bounce Rate Day Visitors4 45 5 295 52 6 76 Bounce Rate VisitorsDay 1 65 432 67 343 78 654 65 565 45 296 52 76
import matplotlib.pyplot as pltfrom matplotlib import stylestyle.use('fivethirtyeight')print(df['Visitors'], df['Bounce Rate'])df['Visitors'].plot()plt.show()df['Bounce Rate'].plot()plt.show()df.plot()plt.show()print(df[['Visitors','Bounce Rate']])
Day1 432 343 654 565 296 76Name: Visitors, dtype: int64 Day1 652 673 784 655 456 52Name: Bounce Rate, dtype: int64
Visitors Bounce RateDay 1 43 652 34 673 65 784 56 655 29 456 76 52
2、IO Basics - Data Analysis with Python and Pandas Tutorial
#import pandas as pd#import quandl#df = quandl.get("ZILLOW/Z77006_ZRIFAH")#print(df.head())#import matplotlib.pyplot as plt#from matplotlib import style#plt.figure(figsize=(8,4))#style.use('fivethirtyeight')#print(df['Value'])#df['Value'].plot()#plt.show()
import pandas as pddf = pd.read_csv('ZILLOW-N15727_PLPRCO.csv')print(df.head())df.set_index('Date', inplace=True)df.to_csv('newcsv2.csv') #regenerating new csv file
Date Value0 2017-06-30 8.9285711 2017-05-31 1.8867922 2017-04-30 8.4745763 2017-03-31 2.8985514 2017-02-28 4.615385
df = pd.read_csv('newcsv2.csv')print(df.head())df = pd.read_csv('newcsv2.csv', index_col=0)print(df.head())
Date Value0 2017-06-30 8.9285711 2017-05-31 1.8867922 2017-04-30 8.4745763 2017-03-31 2.8985514 2017-02-28 4.615385 ValueDate 2017-06-30 8.9285712017-05-31 1.8867922017-04-30 8.4745762017-03-31 2.8985512017-02-28 4.615385
df.columns = ['Austin_HPI']print(df.head())
Austin_HPIDate 2017-06-30 8.9285712017-05-31 1.8867922017-04-30 8.4745762017-03-31 2.8985512017-02-28 4.615385
df.to_csv('newcsv3.csv')df.to_csv('newcsv4.csv', header=False)print(df.head())
Austin_HPIDate 2017-06-30 8.9285712017-05-31 1.8867922017-04-30 8.4745762017-03-31 2.8985512017-02-28 4.615385
df = pd.read_csv('newcsv4.csv', names=['Date', 'Austin_HPI'])print(df.head())
Date Austin_HPI0 2017-06-30 8.9285711 2017-05-31 1.8867922 2017-04-30 8.4745763 2017-03-31 2.8985514 2017-02-28 4.615385
df.to_html('example.html') #regenerating new html file
df = pd.read_csv('newcsv4.csv',names=['Date','Austin_HPI'])print(df.head())
Date Austin_HPI0 2017-06-30 8.9285711 2017-05-31 1.8867922 2017-04-30 8.4745763 2017-03-31 2.8985514 2017-02-28 4.615385
df.rename(columns={'Austin_HPI':'House_Prices'}, inplace=True)print(df.head())
Date House_Prices0 2017-06-30 8.9285711 2017-05-31 1.8867922 2017-04-30 8.4745763 2017-03-31 2.8985514 2017-02-28 4.615385
3、Building dataset - Data Analysis with Python and Pandas Tutorial
import pandas as pdfiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')print(fiddy_states)
[ 0 1 2 30 Abbreviation State Name Capital Became a State1 AL Alabama Montgomery December 14, 18192 AK Alaska Juneau January 3, 19593 AZ Arizona Phoenix February 14, 19124 AR Arkansas Little Rock June 15, 18365 CA California Sacramento September 9, 18506 CO Colorado Denver August 1, 18767 CT Connecticut Hartford January 9, 17888 DE Delaware Dover December 7, 17879 FL Florida Tallahassee March 3, 184510 GA Georgia Atlanta January 2, 178811 HI Hawaii Honolulu August 21, 195912 ID Idaho Boise July 3, 189013 IL Illinois Springfield December 3, 181814 IN Indiana Indianapolis December 11, 181615 IA Iowa Des Moines December 28, 184616 KS Kansas Topeka January 29, 186117 KY Kentucky Frankfort June 1, 179218 LA Louisiana Baton Rouge April 30, 181219 ME Maine Augusta March 15, 182020 MD Maryland Annapolis April 28, 178821 MA Massachusetts Boston February 6, 178822 MI Michigan Lansing January 26, 183723 MN Minnesota Saint Paul May 11, 185824 MS Mississippi Jackson December 10, 181725 MO Missouri Jefferson City August 10, 182126 MT Montana Helena November 8, 188927 NE Nebraska Lincoln March 1, 186728 NV Nevada Carson City October 31, 186429 NH New Hampshire Concord June 21, 178830 NJ New Jersey Trenton December 18, 178731 NM New Mexico Santa Fe January 6, 191232 NY New York Albany July 26, 178833 NC North Carolina Raleigh November 21, 178934 ND North Dakota Bismarck November 2, 188935 OH Ohio Columbus March 1, 180336 OK Oklahoma Oklahoma City November 16, 190737 OR Oregon Salem February 14, 185938 PA Pennsylvania Harrisburg December 12, 178739 RI Rhode Island Providence May 19, 179040 SC South Carolina Columbia May 23, 178841 SD South Dakota Pierre November 2, 188942 TN Tennessee Nashville June 1, 179643 TX Texas Austin December 29, 184544 UT Utah Salt Lake City January 4, 189645 VT Vermont Montpelier March 4, 179146 VA Virginia Richmond June 25, 178847 WA Washington Olympia November 11, 188948 WV West Virginia Charleston June 20, 186349 WI Wisconsin Madison May 29, 184850 WY Wyoming Cheyenne July 10, 1890, 0 \0 v t e Political divisions of the United States... 1 v t e Political divisions of the United States 2 NaN 3 States 4 NaN 5 National capital 6 NaN 7 Large islands 8 NaN 9 Small islands 1 2 3 \0 v t e Political divisions of the United States NaN States 1 NaN NaN NaN 2 NaN NaN NaN 3 Alabama · Alaska · Arizona · Arkansas · Califo... NaN NaN 4 NaN NaN NaN 5 District of Columbia NaN NaN 6 NaN NaN NaN 7 American Samoa · Guam · Northern Mariana Islan... NaN NaN 8 NaN NaN NaN 9 Baker Island · Howland Island · Jarvis Island ... NaN NaN 4 5 6 \0 Alabama · Alaska · Arizona · Arkansas · Califo... NaN National capital 1 NaN NaN NaN 2 NaN NaN NaN 3 NaN NaN NaN 4 NaN NaN NaN 5 NaN NaN NaN 6 NaN NaN NaN 7 NaN NaN NaN 8 NaN NaN NaN 9 NaN NaN NaN 7 8 9 \0 District of Columbia NaN Large islands 1 NaN NaN NaN 2 NaN NaN NaN 3 NaN NaN NaN 4 NaN NaN NaN 5 NaN NaN NaN 6 NaN NaN NaN 7 NaN NaN NaN 8 NaN NaN NaN 9 NaN NaN NaN 10 11 12 \0 American Samoa · Guam · Northern Mariana Islan... NaN Small islands 1 NaN NaN NaN 2 NaN NaN NaN 3 NaN NaN NaN 4 NaN NaN NaN 5 NaN NaN NaN 6 NaN NaN NaN 7 NaN NaN NaN 8 NaN NaN NaN 9 NaN NaN NaN 13 0 Baker Island · Howland Island · Jarvis Island ... 1 NaN 2 NaN 3 NaN 4 NaN 5 NaN 6 NaN 7 NaN 8 NaN 9 NaN , 0 \0 v t e Political divisions of the United States 1 NaN 2 States 3 NaN 4 National capital 5 NaN 6 Large islands 7 NaN 8 Small islands 1 0 NaN 1 NaN 2 Alabama · Alaska · Arizona · Arkansas · Califo... 3 NaN 4 District of Columbia 5 NaN 6 American Samoa · Guam · Northern Mariana Islan... 7 NaN 8 Baker Island · Howland Island · Jarvis Island ... ]
for abbv in fiddy_states[0][0][1:]: print(abbv)
ALAKAZARCACOCTDEFLGAHIIDILINIAKSKYLAMEMDMAMIMNMSMOMTNENVNHNJNMNYNCNDOHOKORPARISCSDTNTXUTVTVAWAWVWIWY
for abbv in fiddy_states[0][0][1:]: #print(abbv) print("FMAC/HPI_"+str(abbv))
FMAC/HPI_ALFMAC/HPI_AKFMAC/HPI_AZFMAC/HPI_ARFMAC/HPI_CAFMAC/HPI_COFMAC/HPI_CTFMAC/HPI_DEFMAC/HPI_FLFMAC/HPI_GAFMAC/HPI_HIFMAC/HPI_IDFMAC/HPI_ILFMAC/HPI_INFMAC/HPI_IAFMAC/HPI_KSFMAC/HPI_KYFMAC/HPI_LAFMAC/HPI_MEFMAC/HPI_MDFMAC/HPI_MAFMAC/HPI_MIFMAC/HPI_MNFMAC/HPI_MSFMAC/HPI_MOFMAC/HPI_MTFMAC/HPI_NEFMAC/HPI_NVFMAC/HPI_NHFMAC/HPI_NJFMAC/HPI_NMFMAC/HPI_NYFMAC/HPI_NCFMAC/HPI_NDFMAC/HPI_OHFMAC/HPI_OKFMAC/HPI_ORFMAC/HPI_PAFMAC/HPI_RIFMAC/HPI_SCFMAC/HPI_SDFMAC/HPI_TNFMAC/HPI_TXFMAC/HPI_UTFMAC/HPI_VTFMAC/HPI_VAFMAC/HPI_WAFMAC/HPI_WVFMAC/HPI_WIFMAC/HPI_WY
4、Concatenating and Appending dataframes - Data Analysis with Python and Pandas Tutorial
import pandas as pddf1 = pd.DataFrame({'HPI':[80,85,88,85], 'Int_rate':[2, 3, 2, 2], 'US_GDP_Thousands':[50, 55, 65, 55]}, index = [2001, 2002, 2003, 2004])df2 = pd.DataFrame({'HPI':[80,85,88,85], 'Int_rate':[2, 3, 2, 2], 'US_GDP_Thousands':[50, 55, 65, 55]}, index = [2005, 2006, 2007, 2008])df3 = pd.DataFrame({'HPI':[80,85,88,85], 'Int_rate':[2, 3, 2, 2], 'Low_tier_HPI':[50, 52, 50, 53]}, index = [2001, 2002, 2003, 2004])
concat = pd.concat([df1,df2])print(concat)
HPI Int_rate US_GDP_Thousands2001 80 2 502002 85 3 552003 88 2 652004 85 2 552005 80 2 502006 85 3 552007 88 2 652008 85 2 55
concat = pd.concat([df1,df2,df3])print(concat)
HPI Int_rate Low_tier_HPI US_GDP_Thousands2001 80 2 NaN 50.02002 85 3 NaN 55.02003 88 2 NaN 65.02004 85 2 NaN 55.02005 80 2 NaN 50.02006 85 3 NaN 55.02007 88 2 NaN 65.02008 85 2 NaN 55.02001 80 2 50.0 NaN2002 85 3 52.0 NaN2003 88 2 50.0 NaN2004 85 2 53.0 NaN
df4 = df1.append(df2)print(df4)
HPI Int_rate US_GDP_Thousands2001 80 2 502002 85 3 552003 88 2 652004 85 2 552005 80 2 502006 85 3 552007 88 2 652008 85 2 55
df4 = df1.append(df3)print(df4)
HPI Int_rate Low_tier_HPI US_GDP_Thousands2001 80 2 NaN 50.02002 85 3 NaN 55.02003 88 2 NaN 65.02004 85 2 NaN 55.02001 80 2 50.0 NaN2002 85 3 52.0 NaN2003 88 2 50.0 NaN2004 85 2 53.0 NaN
s = pd.Series([80,2,50], index=['HPI','Int_rate','US_GDP_Thousands'])print(s)df4 = df1.append(s, ignore_index=True)print(df4)
HPI 80Int_rate 2US_GDP_Thousands 50dtype: int64 HPI Int_rate US_GDP_Thousands0 80 2 501 85 3 552 88 2 653 85 2 554 80 2 50
5、Joining and Merging Dataframes - Data Analysis with Python and Pandas Tutorial
import pandas as pddf1 = pd.DataFrame({'HPI':[80,85,88,85], 'Int_rate':[2, 3, 2, 2], 'US_GDP_Thousands':[50, 55, 65, 55]}, index = [2001, 2002, 2003, 2004])df2 = pd.DataFrame({'HPI':[80,85,88,85], 'Int_rate':[2, 3, 2, 2], 'US_GDP_Thousands':[50, 55, 65, 55]}, index = [2005, 2006, 2007, 2008])df3 = pd.DataFrame({'HPI':[80,85,88,85], 'Unemployment':[7, 8, 9, 6], 'Low_tier_HPI':[50, 52, 50, 53]}, index = [2001, 2002, 2003, 2004])
print(pd.merge(df1,df3, on='HPI'))
HPI Int_rate US_GDP_Thousands Low_tier_HPI Unemployment0 80 2 50 50 71 85 3 55 52 82 85 3 55 53 63 85 2 55 52 84 85 2 55 53 65 88 2 65 50 9
print(pd.merge(df1,df2, on=['HPI','Int_rate']))
HPI Int_rate US_GDP_Thousands_x US_GDP_Thousands_y0 80 2 50 501 85 3 55 552 88 2 65 653 85 2 55 55
df4 = pd.merge(df1,df3, on='HPI')df4.set_index('HPI', inplace=True)print(df4)
Int_rate US_GDP_Thousands Low_tier_HPI UnemploymentHPI 80 2 50 50 785 3 55 52 885 3 55 53 685 2 55 52 885 2 55 53 688 2 65 50 9
df1.set_index('HPI', inplace=True)df3.set_index('HPI', inplace=True)joined = df1.join(df3)print(joined)
Int_rate US_GDP_Thousands Low_tier_HPI UnemploymentHPI 80 2 50 50 785 3 55 52 885 3 55 53 685 2 55 52 885 2 55 53 688 2 65 50 9
df1 = pd.DataFrame({ 'Int_rate':[2, 3, 2, 2], 'US_GDP_Thousands':[50, 55, 65, 55], 'Year':[2001, 2002, 2003, 2004] })df3 = pd.DataFrame({ 'Unemployment':[7, 8, 9, 6], 'Low_tier_HPI':[50, 52, 50, 53], 'Year':[2001, 2003, 2004, 2005]})
merged = pd.merge(df1,df3, on='Year')print(merged)
Int_rate US_GDP_Thousands Year Low_tier_HPI Unemployment0 2 50 2001 50 71 2 65 2003 52 82 2 55 2004 50 9
merged = pd.merge(df1,df3, on='Year')merged.set_index('Year', inplace=True)print(merged)
Int_rate US_GDP_Thousands Low_tier_HPI UnemploymentYear 2001 2 50 50 72003 2 65 52 82004 2 55 50 9
merged = pd.merge(df1,df3, on='Year', how='left')print(merged)merged.set_index('Year', inplace=True)print(merged)
Int_rate US_GDP_Thousands Year Low_tier_HPI Unemployment0 2 50 2001 50.0 7.01 3 55 2002 NaN NaN2 2 65 2003 52.0 8.03 2 55 2004 50.0 9.0 Int_rate US_GDP_Thousands Low_tier_HPI UnemploymentYear 2001 2 50 50.0 7.02002 3 55 NaN NaN2003 2 65 52.0 8.02004 2 55 50.0 9.0
merged = pd.merge(df1,df3, on='Year', how='right')merged.set_index('Year', inplace=True)print(merged)
Int_rate US_GDP_Thousands Low_tier_HPI UnemploymentYear 2001.0 2.0 50.0 50 72003.0 2.0 65.0 52 82004.0 2.0 55.0 50 92005.0 NaN NaN 53 6
merged = pd.merge(df1,df3, on='Year', how='outer')merged.set_index('Year', inplace=True)print(merged)
Int_rate US_GDP_Thousands Low_tier_HPI UnemploymentYear 2001.0 2.0 50.0 50.0 7.02002.0 3.0 55.0 NaN NaN2003.0 2.0 65.0 52.0 8.02004.0 2.0 55.0 50.0 9.02005.0 NaN NaN 53.0 6.0
merged = pd.merge(df1,df3, on='Year', how='inner')merged.set_index('Year', inplace=True)print(merged)
Int_rate US_GDP_Thousands Low_tier_HPI UnemploymentYear 2001 2 50 50 72003 2 65 52 82004 2 55 50 9
df1.set_index('Year', inplace=True)df3.set_index('Year', inplace=True)joined = df1.join(df3, how="outer")print(joined)
Int_rate US_GDP_Thousands Low_tier_HPI UnemploymentYear 2001 2.0 50.0 50.0 7.02002 3.0 55.0 NaN NaN2003 2.0 65.0 52.0 8.02004 2.0 55.0 50.0 9.02005 NaN NaN 53.0 6.0
6、Pickling - Data Analysis with Python and Pandas Tutorial
import quandlimport pandas as pd# Not necessary, I just do this so I do not show my API key.#api_key = open('quandlapikey.txt','r').read()fiddy_states = pd.read_html('https://simple.wikipedia.org/wiki/List_of_U.S._states')#print(fiddy_states)main_df = pd.DataFrame()for abbv in fiddy_states[0][0][1:]: #print(abbv) query = "FMAC/HPI_"+str(abbv) df = quandl.get(query, authtoken='n75cJa9b8mNzuVz65S1S') df.columns = [str(abbv)] if main_df.empty: main_df = df else: main_df = main_df.join(df)print(main_df.head())
AL AK AZ AR CA CO \Date 1975-01-31 35.453384 34.385997 28.940587 36.845816 15.696667 19.647452 1975-02-28 35.666686 34.910701 29.476038 37.185864 15.747528 19.875307 1975-03-31 35.915007 35.446987 29.980514 37.482491 15.936916 20.102116 1975-04-30 36.216014 36.002154 30.372962 37.722278 16.249400 20.315570 1975-05-31 36.494630 36.599658 30.577860 37.947634 16.509738 20.494853 CT DE FL GA ... SD \Date ... 1975-01-31 24.493861 27.256874 31.036368 30.746130 ... 37.754067 1975-02-28 25.032651 27.249036 32.252269 30.471590 ... 37.337158 1975-03-31 25.440129 27.272794 34.035890 30.358694 ... 36.912611 1975-04-30 25.669265 27.372090 36.222625 30.421525 ... 36.489475 1975-05-31 25.738778 27.575029 36.457310 30.530216 ... 36.102422 TN TX UT VT VA WA \Date 1975-01-31 32.171503 32.626112 24.593496 26.620695 27.901501 17.478975 1975-02-28 32.222504 32.958338 24.947068 26.937920 28.192244 17.544439 1975-03-31 32.312085 33.546541 25.262533 27.244899 28.407625 17.652704 1975-04-30 32.439126 34.398979 25.510183 27.525197 28.570828 17.785996 1975-05-31 32.585102 34.651415 25.671483 27.771740 28.712080 17.910147 WV WI WY Date 1975-01-31 41.006639 28.115545 31.663002 1975-02-28 42.051072 28.490112 32.157887 1975-03-31 43.139021 28.861735 32.678700 1975-04-30 44.260809 29.197658 33.211169 1975-05-31 45.388703 29.476274 33.718382 [5 rows x 50 columns]
import quandlimport pandas as pdimport pickle# Not necessary, I just do this so I do not show my API key.#api_key = open('quandlapikey.txt','r').read()#print(fiddy_states)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_data(): states = state_list() main_df = pd.DataFrame() for abbv in states: #print(abbv) query = "FMAC/HPI_"+str(abbv) df = quandl.get(query, authtoken='n75cJa9b8mNzuVz65S1S') df.columns = [str(abbv)] 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()grab_initial_state_data()
AL AK AZ AR CA CO \Date 1975-01-31 35.453384 34.385997 28.940587 36.845816 15.696667 19.647452 1975-02-28 35.666686 34.910701 29.476038 37.185864 15.747528 19.875307 1975-03-31 35.915007 35.446987 29.980514 37.482491 15.936916 20.102116 1975-04-30 36.216014 36.002154 30.372962 37.722278 16.249400 20.315570 1975-05-31 36.494630 36.599658 30.577860 37.947634 16.509738 20.494853 CT DE FL GA ... SD \Date ... 1975-01-31 24.493861 27.256874 31.036368 30.746130 ... 37.754067 1975-02-28 25.032651 27.249036 32.252269 30.471590 ... 37.337158 1975-03-31 25.440129 27.272794 34.035890 30.358694 ... 36.912611 1975-04-30 25.669265 27.372090 36.222625 30.421525 ... 36.489475 1975-05-31 25.738778 27.575029 36.457310 30.530216 ... 36.102422 TN TX UT VT VA WA \Date 1975-01-31 32.171503 32.626112 24.593496 26.620695 27.901501 17.478975 1975-02-28 32.222504 32.958338 24.947068 26.937920 28.192244 17.544439 1975-03-31 32.312085 33.546541 25.262533 27.244899 28.407625 17.652704 1975-04-30 32.439126 34.398979 25.510183 27.525197 28.570828 17.785996 1975-05-31 32.585102 34.651415 25.671483 27.771740 28.712080 17.910147 WV WI WY Date 1975-01-31 41.006639 28.115545 31.663002 1975-02-28 42.051072 28.490112 32.157887 1975-03-31 43.139021 28.861735 32.678700 1975-04-30 44.260809 29.197658 33.211169 1975-05-31 45.388703 29.476274 33.718382 [5 rows x 50 columns]
pickle_in = open('fiddy_states.pickle','rb')HPI_data = pickle.load(pickle_in)print(HPI_data)
AL AK AZ AR CA \Date 1975-01-31 35.453384 34.385997 28.940587 36.845816 15.696667 1975-02-28 35.666686 34.910701 29.476038 37.185864 15.747528 1975-03-31 35.915007 35.446987 29.980514 37.482491 15.936916 1975-04-30 36.216014 36.002154 30.372962 37.722278 16.249400 1975-05-31 36.494630 36.599658 30.577860 37.947634 16.509738 1975-06-30 36.634853 37.228477 30.527373 38.181553 16.625954 1975-07-31 36.574284 37.850604 30.201374 38.387207 16.750543 1975-08-31 36.355267 38.416847 29.687453 38.516980 16.974333 1975-09-30 36.107410 38.912039 29.152543 38.534432 17.216349 1975-10-31 35.991610 39.365282 28.850928 38.496009 17.432255 1975-11-30 36.095651 39.772512 28.957720 38.525691 17.576145 1975-12-31 36.435524 40.113479 29.328103 38.657338 17.699161 1976-01-31 36.978830 40.389793 29.711190 38.859577 17.880677 1976-02-29 37.597955 40.622892 30.003192 39.150075 18.095021 1976-03-31 38.124589 40.839218 30.175684 39.542395 18.363835 1976-04-30 38.456250 41.050961 30.238646 39.985721 18.657621 1976-05-31 38.614078 41.259609 30.230365 40.379474 18.880866 1976-06-30 38.682492 41.461078 30.195239 40.691074 19.109120 1976-07-31 38.751361 41.633066 30.185145 40.978526 19.407544 1976-08-31 38.820408 41.768158 30.221197 41.287394 19.708868 1976-09-30 38.864600 41.934490 30.285878 41.554545 19.987500 1976-10-31 38.927183 42.194947 30.438921 41.719865 20.279428 1976-11-30 39.070733 42.544022 30.673730 41.844728 20.637096 1976-12-31 39.233851 42.955853 30.862350 42.016912 20.994290 1977-01-31 39.324173 43.387346 30.975695 42.299034 21.359735 1977-02-28 39.370142 43.785317 31.098255 42.690048 21.834891 1977-03-31 39.436033 44.105789 31.328894 43.105086 22.417219 1977-04-30 39.624060 44.351466 31.615716 43.442488 22.995164 1977-05-31 39.951459 44.566462 31.861496 43.684871 23.589262 1977-06-30 40.371169 44.780218 32.176042 43.916942 24.185939 ... ... ... ... ... ... 2015-01-31 123.214683 167.290833 150.805333 129.293714 179.387082 2015-02-28 123.714096 167.769475 151.788730 129.343300 180.866188 2015-03-31 124.432426 168.937698 153.163623 129.922592 183.443491 2015-04-30 125.379319 170.694759 154.671203 130.922776 185.977073 2015-05-31 126.410371 172.690741 156.047095 132.092783 187.945700 2015-06-30 127.311924 174.406563 157.134850 133.067558 189.478706 2015-07-31 127.809975 175.466556 158.083390 133.834926 190.516613 2015-08-31 127.801120 175.931999 158.994290 134.470507 191.287656 2015-09-30 127.288536 175.920868 159.893900 134.829295 191.737526 2015-10-31 126.674812 175.563682 160.379977 134.744542 192.092512 2015-11-30 126.214000 175.246454 160.467723 134.254223 192.637783 2015-12-31 125.984065 175.026028 160.583240 133.591856 193.216018 2016-01-31 126.273672 174.846377 161.143328 133.079416 193.709823 2016-02-29 127.114005 174.922916 162.635643 133.127573 195.532746 2016-03-31 128.269958 175.447264 164.736865 133.924852 198.522169 2016-04-30 129.650019 176.370721 166.503995 135.126513 200.729583 2016-05-31 130.934649 177.339580 167.446295 136.295392 202.385206 2016-06-30 131.957802 177.784191 168.112302 137.268921 203.950735 2016-07-31 132.765743 177.444544 169.084497 137.833235 205.084637 2016-08-31 133.116480 176.586280 170.183068 137.911100 205.605572 2016-09-30 132.894906 175.658243 171.361328 137.727023 205.646279 2016-10-31 132.150048 175.040074 172.648750 137.396834 205.864743 2016-11-30 131.338689 174.774483 173.538287 137.174554 206.328398 2016-12-31 130.914417 174.697186 174.119096 137.266561 207.231568 2017-01-31 131.101733 174.848165 174.911735 137.558812 208.374611 2017-02-28 132.054144 175.422420 175.877670 138.104003 209.865420 2017-03-31 133.590020 176.406371 177.315270 139.067406 212.093923 2017-04-30 135.203788 177.726428 179.073405 140.321974 214.612943 2017-05-31 136.498215 179.203841 180.297286 141.572719 217.093456 2017-06-30 137.712352 180.405983 181.100072 142.689749 218.899302 CO CT DE FL GA \Date 1975-01-31 19.647452 24.493861 27.256874 31.036368 30.746130 1975-02-28 19.875307 25.032651 27.249036 32.252269 30.471590 1975-03-31 20.102116 25.440129 27.272794 34.035890 30.358694 1975-04-30 20.315570 25.669265 27.372090 36.222625 30.421525 1975-05-31 20.494853 25.738778 27.575029 36.457310 30.530216 1975-06-30 20.651234 25.704588 27.831925 34.815122 30.561757 1975-07-31 20.765025 25.653661 28.067595 33.585945 30.461846 1975-08-31 20.773227 25.634210 28.270963 33.012826 30.219990 1975-09-30 20.706608 25.658333 28.441906 32.878150 29.872967 1975-10-31 20.688197 25.734995 28.557490 33.009574 29.587931 1975-11-30 20.814759 25.905826 28.632126 33.263831 29.500462 1975-12-31 21.038689 26.135594 28.689278 33.409853 29.556919 1976-01-31 21.255645 26.342346 28.718473 33.373301 29.646579 1976-02-29 21.438718 26.490259 28.720166 33.389839 29.668915 1976-03-31 21.621099 26.584399 28.727504 33.932085 29.632195 1976-04-30 21.792312 26.656375 28.791011 35.154826 29.671058 1976-05-31 21.909956 26.734638 28.885535 35.487947 29.878039 1976-06-30 21.979575 26.855000 28.940313 34.629923 30.283138 1976-07-31 22.009310 27.025475 28.944659 34.033513 30.734291 1976-08-31 22.008362 27.166350 28.919844 33.921707 30.973968 1976-09-30 22.032409 27.239081 28.893143 34.027834 31.028048 1976-10-31 22.173065 27.324569 28.909225 34.133866 30.981488 1976-11-30 22.440542 27.393190 29.007428 34.200512 30.881753 1976-12-31 22.721354 27.354598 29.182626 34.061910 30.811641 1977-01-31 22.933155 27.275330 29.402921 33.577663 30.784891 1977-02-28 23.109582 27.246175 29.620419 32.890087 30.822328 1977-03-31 23.307137 27.324545 29.773347 33.012283 30.925928 1977-04-30 23.577776 27.621353 29.833276 34.777339 31.088212 1977-05-31 23.916893 28.112667 29.825291 35.992038 31.285932 1977-06-30 24.314146 28.656180 29.812207 35.536988 31.499936 ... ... ... ... ... ... 2015-01-31 144.167659 128.930628 147.539868 156.288395 115.926268 2015-02-28 146.284656 128.731928 147.499368 158.026599 116.940183 2015-03-31 148.787298 129.501519 148.110160 160.022443 118.515241 2015-04-30 151.226946 131.103544 149.408683 161.889730 120.267075 2015-05-31 153.509348 132.981211 150.877619 164.167326 121.714831 2015-06-30 155.288726 134.466828 151.743217 166.451645 122.729749 2015-07-31 156.425206 135.065680 151.843141 168.120303 123.278571 2015-08-31 156.888998 134.488097 151.741030 169.009810 123.587220 2015-09-30 157.064733 133.132658 151.850814 169.732543 123.898885 2015-10-31 157.190599 131.961233 152.312323 170.843980 124.145452 2015-11-30 157.048440 131.161984 152.985548 171.812399 124.174661 2015-12-31 157.307790 130.343517 153.464272 172.210638 124.276509 2016-01-31 158.660182 129.648250 153.649657 172.643866 124.613819 2016-02-29 160.952065 129.513436 153.718342 174.353115 125.323799 2016-03-31 163.899156 130.110334 153.939635 177.187484 126.762679 2016-04-30 166.958739 131.412487 154.417719 179.602582 128.884442 2016-05-31 169.664346 132.903451 154.884881 181.562912 130.801806 2016-06-30 171.581083 134.087932 155.215671 183.548631 131.902469 2016-07-31 172.648655 134.552888 155.376120 185.128708 132.516847 2016-08-31 173.086107 134.030144 155.206991 186.414106 132.691453 2016-09-30 173.227900 133.270077 154.710212 187.430137 132.674728 2016-10-31 173.385423 132.789329 154.082988 188.299249 132.747039 2016-11-30 173.566781 132.353426 153.524609 189.018972 132.740394 2016-12-31 174.341632 131.808821 152.978762 189.844825 132.738755 2017-01-31 176.120468 131.291994 152.649917 191.190460 133.094885 2017-02-28 178.562359 131.116584 152.963522 192.906654 134.047852 2017-03-31 181.220486 131.925410 154.149283 194.836579 135.683034 2017-04-30 183.680417 133.951730 155.887776 196.925531 137.823245 2017-05-31 186.187747 136.547673 157.638196 198.450983 139.670085 2017-06-30 187.976054 138.524640 159.252241 199.987057 140.914383 ... SD TN TX UT \Date ... 1975-01-31 ... 37.754067 32.171503 32.626112 24.593496 1975-02-28 ... 37.337158 32.222504 32.958338 24.947068 1975-03-31 ... 36.912611 32.312085 33.546541 25.262533 1975-04-30 ... 36.489475 32.439126 34.398979 25.510183 1975-05-31 ... 36.102422 32.585102 34.651415 25.671483 1975-06-30 ... 35.806520 32.744740 34.222331 25.718573 1975-07-31 ... 35.610109 32.911205 33.930958 25.658370 1975-08-31 ... 35.463960 33.086491 33.890084 25.570250 1975-09-30 ... 35.342593 33.315025 33.965869 25.551407 1975-10-31 ... 35.262108 33.656965 34.082889 25.716519 1975-11-30 ... 35.246260 34.109196 34.303998 26.077244 1975-12-31 ... 35.319802 34.516641 34.509390 26.473878 1976-01-31 ... 35.499957 34.707167 34.643401 26.824573 1976-02-29 ... 35.790652 34.681294 34.952800 27.156097 1976-03-31 ... 36.161829 34.597537 35.688706 27.459836 1976-04-30 ... 36.556026 34.624454 36.720822 27.732824 1976-05-31 ... 36.933173 34.719060 37.037879 27.951893 1976-06-30 ... 37.273964 34.745390 36.642609 28.087228 1976-07-31 ... 37.592575 34.741913 36.446191 28.223297 1976-08-31 ... 37.888156 34.794782 36.453791 28.396717 1976-09-30 ... 38.100695 34.894346 36.552274 28.539690 1976-10-31 ... 38.172081 35.002671 36.765258 28.673632 1976-11-30 ... 38.119135 35.105316 37.070697 28.881504 1976-12-31 ... 38.038400 35.235608 37.279759 29.193845 1977-01-31 ... 38.013313 35.454168 37.445796 29.548910 1977-02-28 ... 38.081055 35.792957 37.882246 29.907678 1977-03-31 ... 38.276353 36.224945 38.933838 30.304096 1977-04-30 ... 38.647993 36.688615 40.603675 30.756327 1977-05-31 ... 39.199588 37.123652 40.913325 31.233794 1977-06-30 ... 39.866278 37.551632 39.924533 31.699209 ... ... ... ... ... ... 2015-01-31 ... 150.388726 133.871790 156.835154 147.177031 2015-02-28 ... 151.110585 134.620494 158.017454 148.588786 2015-03-31 ... 152.333628 135.857941 159.871952 150.441126 2015-04-30 ... 153.697091 137.325002 161.755716 152.320416 2015-05-31 ... 154.904534 138.881299 163.527696 154.033833 2015-06-30 ... 155.872554 140.135567 165.243458 155.323979 2015-07-31 ... 156.579706 140.816036 166.371662 156.134630 2015-08-31 ... 157.007037 141.180401 166.542478 156.695655 2015-09-30 ... 157.303222 141.501492 166.665983 157.220849 2015-10-31 ... 157.629249 141.716678 167.182878 157.736346 2015-11-30 ... 157.893027 141.642814 167.494674 158.065307 2015-12-31 ... 158.159982 141.427437 167.532281 158.416922 2016-01-31 ... 158.494928 141.547459 168.158064 159.146505 2016-02-29 ... 158.822537 142.264027 169.810792 160.198260 2016-03-31 ... 159.279722 143.658095 171.539418 161.820369 2016-04-30 ... 160.045885 145.600353 173.256735 164.246382 2016-05-31 ... 161.268283 147.363228 175.303755 166.563808 2016-06-30 ... 162.843363 148.476246 176.800415 168.133279 2016-07-31 ... 164.253934 149.491748 177.724614 169.366037 2016-08-31 ... 165.176550 150.669847 178.572709 170.199149 2016-09-30 ... 165.446796 151.391978 179.165056 170.459830 2016-10-31 ... 164.878105 151.439237 179.267350 170.234772 2016-11-30 ... 163.777107 151.329018 179.011867 169.817316 2016-12-31 ... 162.867985 151.241392 178.993963 169.848764 2017-01-31 ... 162.658626 151.575136 180.056846 170.985925 2017-02-28 ... 163.232106 152.857818 181.843074 173.282842 2017-03-31 ... 164.585344 154.599873 183.832887 175.951227 2017-04-30 ... 166.576154 156.280502 186.446220 178.208219 2017-05-31 ... 168.838073 157.697551 188.999583 180.104079 2017-06-30 ... 170.881416 158.797167 191.145051 181.469212 VT VA WA WV WI \Date 1975-01-31 26.620695 27.901501 17.478975 41.006639 28.115545 1975-02-28 26.937920 28.192244 17.544439 42.051072 28.490112 1975-03-31 27.244899 28.407625 17.652704 43.139021 28.861735 1975-04-30 27.525197 28.570828 17.785996 44.260809 29.197658 1975-05-31 27.771740 28.712080 17.910147 45.388703 29.476274 1975-06-30 27.990373 28.850736 18.042067 46.463410 29.691981 1975-07-31 28.170273 29.044530 18.187802 47.405677 29.860880 1975-08-31 28.289204 29.242400 18.277487 48.156768 30.009379 1975-09-30 28.350415 29.305152 18.284039 48.659907 30.201191 1975-10-31 28.372390 29.251568 18.300061 48.881559 30.423250 1975-11-30 28.367012 29.157374 18.431764 48.888419 30.572815 1975-12-31 28.339887 29.052615 18.647899 48.790877 30.626502 1976-01-31 28.294290 28.973904 18.867923 48.673086 30.633439 1976-02-29 28.239803 29.018855 19.090844 48.618452 30.625383 1976-03-31 28.206607 29.201592 19.304640 48.656525 30.648633 1976-04-30 28.239656 29.429079 19.498190 48.730556 30.769416 1976-05-31 28.355536 29.674373 19.721004 48.779634 30.982752 1976-06-30 28.545312 29.887655 20.029470 48.776707 31.182373 1976-07-31 28.791784 30.027575 20.423411 48.719739 31.339649 1976-08-31 29.064077 30.185942 20.767478 48.642864 31.521193 1976-09-30 29.326231 30.349356 20.963020 48.596298 31.735860 1976-10-31 29.551156 30.464092 21.092221 48.598991 31.944387 1976-11-30 29.735081 30.579152 21.269940 48.663287 32.191967 1976-12-31 29.890396 30.677420 21.482062 48.821202 32.515778 1977-01-31 30.027569 30.760146 21.641866 49.098619 32.878675 1977-02-28 30.155120 30.894382 21.809690 49.481909 33.304425 1977-03-31 30.296011 31.101357 22.125344 49.947511 33.800142 1977-04-30 30.475071 31.348194 22.626472 50.489419 34.284364 1977-05-31 30.705529 31.639371 23.173477 51.049705 34.757529 1977-06-30 30.983867 31.975911 23.670298 51.554349 35.339741 ... ... ... ... ... ... 2015-01-31 157.202112 168.439563 158.042651 139.866172 119.615921 2015-02-28 157.829665 168.541470 159.704842 140.318073 120.092465 2015-03-31 159.273148 169.861735 162.428411 141.519823 121.304395 2015-04-30 161.503688 171.801426 165.417879 143.100354 122.966455 2015-05-31 164.034173 173.639545 167.971869 144.401776 124.927943 2015-06-30 166.033178 174.892157 169.997388 144.945682 126.399787 2015-07-31 166.989955 175.245914 171.581229 144.803141 126.930033 2015-08-31 166.987853 175.114416 172.529522 144.262970 126.933873 2015-09-30 166.365554 174.926488 173.013062 143.524402 126.693759 2015-10-31 165.411259 174.427615 173.652159 142.768395 126.501600 2015-11-30 164.372868 173.579427 174.400987 142.013520 126.301044 2015-12-31 163.504043 172.667656 174.984247 141.263657 125.644494 2016-01-31 162.980355 172.392378 176.124979 140.651142 125.102488 2016-02-29 162.866811 173.490777 178.702477 140.422218 125.615208 2016-03-31 163.246502 175.613691 182.006211 140.841035 127.139877 2016-04-30 164.265165 177.779940 185.190232 141.916831 129.057519 2016-05-31 165.625447 179.683737 187.972140 143.353606 131.047203 2016-06-30 166.942471 180.955316 190.151484 144.612754 132.929595 2016-07-31 167.977912 181.180301 191.792737 145.294723 134.119353 2016-08-31 168.369397 180.926844 192.769997 145.610239 134.413904 2016-09-30 167.972407 180.569133 193.033028 145.875422 134.177277 2016-10-31 167.141612 180.221308 193.034111 145.997822 133.865722 2016-11-30 166.394126 179.609332 193.448931 145.886340 133.160883 2016-12-31 166.015309 178.774034 194.611201 145.429858 132.251746 2017-01-31 166.192565 178.502466 196.443039 144.782388 132.037674 2017-02-28 166.949802 179.613711 199.582264 144.429322 132.606904 2017-03-31 168.049096 182.286286 204.224082 144.741636 134.149181 2017-04-30 169.410542 185.296871 208.884908 145.748552 136.579530 2017-05-31 171.178579 187.538848 212.810431 147.107015 138.864252 2017-06-30 172.565476 189.396040 216.341550 148.077932 140.898320 WY Date 1975-01-31 31.663002 1975-02-28 32.157887 1975-03-31 32.678700 1975-04-30 33.211169 1975-05-31 33.718382 1975-06-30 34.186630 1975-07-31 34.620016 1975-08-31 35.007426 1975-09-30 35.333703 1975-10-31 35.573043 1975-11-30 35.729397 1975-12-31 35.833804 1976-01-31 35.922171 1976-02-29 36.042615 1976-03-31 36.223635 1976-04-30 36.469061 1976-05-31 36.799338 1976-06-30 37.255128 1976-07-31 37.824382 1976-08-31 38.429590 1976-09-30 39.036745 1976-10-31 39.655906 1976-11-30 40.240983 1976-12-31 40.715412 1977-01-31 41.084114 1977-02-28 41.411241 1977-03-31 41.735093 1977-04-30 42.069710 1977-05-31 42.442851 1977-06-30 42.921568 ... ... 2015-01-31 180.064988 2015-02-28 180.356737 2015-03-31 181.067914 2015-04-30 182.365664 2015-05-31 184.081078 2015-06-30 185.850321 2015-07-31 187.127244 2015-08-31 187.440939 2015-09-30 186.909502 2015-10-31 185.912710 2015-11-30 184.709911 2015-12-31 183.679069 2016-01-31 183.194830 2016-02-29 183.401656 2016-03-31 184.247241 2016-04-30 185.442763 2016-05-31 186.526314 2016-06-30 187.348829 2016-07-31 187.997204 2016-08-31 188.463676 2016-09-30 188.474232 2016-10-31 187.790452 2016-11-30 186.767554 2016-12-31 185.988855 2017-01-31 185.784342 2017-02-28 186.212775 2017-03-31 187.118813 2017-04-30 188.385079 2017-05-31 189.901394 2017-06-30 191.424312 [510 rows x 50 columns]
HPI_data.to_pickle('pickle.pickle')HPI_data2 = pd.read_pickle('pickle.pickle')print(HPI_data2)
AL AK AZ AR CA \Date 1975-01-31 35.453384 34.385997 28.940587 36.845816 15.696667 1975-02-28 35.666686 34.910701 29.476038 37.185864 15.747528 1975-03-31 35.915007 35.446987 29.980514 37.482491 15.936916 1975-04-30 36.216014 36.002154 30.372962 37.722278 16.249400 1975-05-31 36.494630 36.599658 30.577860 37.947634 16.509738 1975-06-30 36.634853 37.228477 30.527373 38.181553 16.625954 1975-07-31 36.574284 37.850604 30.201374 38.387207 16.750543 1975-08-31 36.355267 38.416847 29.687453 38.516980 16.974333 1975-09-30 36.107410 38.912039 29.152543 38.534432 17.216349 1975-10-31 35.991610 39.365282 28.850928 38.496009 17.432255 1975-11-30 36.095651 39.772512 28.957720 38.525691 17.576145 1975-12-31 36.435524 40.113479 29.328103 38.657338 17.699161 1976-01-31 36.978830 40.389793 29.711190 38.859577 17.880677 1976-02-29 37.597955 40.622892 30.003192 39.150075 18.095021 1976-03-31 38.124589 40.839218 30.175684 39.542395 18.363835 1976-04-30 38.456250 41.050961 30.238646 39.985721 18.657621 1976-05-31 38.614078 41.259609 30.230365 40.379474 18.880866 1976-06-30 38.682492 41.461078 30.195239 40.691074 19.109120 1976-07-31 38.751361 41.633066 30.185145 40.978526 19.407544 1976-08-31 38.820408 41.768158 30.221197 41.287394 19.708868 1976-09-30 38.864600 41.934490 30.285878 41.554545 19.987500 1976-10-31 38.927183 42.194947 30.438921 41.719865 20.279428 1976-11-30 39.070733 42.544022 30.673730 41.844728 20.637096 1976-12-31 39.233851 42.955853 30.862350 42.016912 20.994290 1977-01-31 39.324173 43.387346 30.975695 42.299034 21.359735 1977-02-28 39.370142 43.785317 31.098255 42.690048 21.834891 1977-03-31 39.436033 44.105789 31.328894 43.105086 22.417219 1977-04-30 39.624060 44.351466 31.615716 43.442488 22.995164 1977-05-31 39.951459 44.566462 31.861496 43.684871 23.589262 1977-06-30 40.371169 44.780218 32.176042 43.916942 24.185939 ... ... ... ... ... ... 2015-01-31 123.214683 167.290833 150.805333 129.293714 179.387082 2015-02-28 123.714096 167.769475 151.788730 129.343300 180.866188 2015-03-31 124.432426 168.937698 153.163623 129.922592 183.443491 2015-04-30 125.379319 170.694759 154.671203 130.922776 185.977073 2015-05-31 126.410371 172.690741 156.047095 132.092783 187.945700 2015-06-30 127.311924 174.406563 157.134850 133.067558 189.478706 2015-07-31 127.809975 175.466556 158.083390 133.834926 190.516613 2015-08-31 127.801120 175.931999 158.994290 134.470507 191.287656 2015-09-30 127.288536 175.920868 159.893900 134.829295 191.737526 2015-10-31 126.674812 175.563682 160.379977 134.744542 192.092512 2015-11-30 126.214000 175.246454 160.467723 134.254223 192.637783 2015-12-31 125.984065 175.026028 160.583240 133.591856 193.216018 2016-01-31 126.273672 174.846377 161.143328 133.079416 193.709823 2016-02-29 127.114005 174.922916 162.635643 133.127573 195.532746 2016-03-31 128.269958 175.447264 164.736865 133.924852 198.522169 2016-04-30 129.650019 176.370721 166.503995 135.126513 200.729583 2016-05-31 130.934649 177.339580 167.446295 136.295392 202.385206 2016-06-30 131.957802 177.784191 168.112302 137.268921 203.950735 2016-07-31 132.765743 177.444544 169.084497 137.833235 205.084637 2016-08-31 133.116480 176.586280 170.183068 137.911100 205.605572 2016-09-30 132.894906 175.658243 171.361328 137.727023 205.646279 2016-10-31 132.150048 175.040074 172.648750 137.396834 205.864743 2016-11-30 131.338689 174.774483 173.538287 137.174554 206.328398 2016-12-31 130.914417 174.697186 174.119096 137.266561 207.231568 2017-01-31 131.101733 174.848165 174.911735 137.558812 208.374611 2017-02-28 132.054144 175.422420 175.877670 138.104003 209.865420 2017-03-31 133.590020 176.406371 177.315270 139.067406 212.093923 2017-04-30 135.203788 177.726428 179.073405 140.321974 214.612943 2017-05-31 136.498215 179.203841 180.297286 141.572719 217.093456 2017-06-30 137.712352 180.405983 181.100072 142.689749 218.899302 CO CT DE FL GA \Date 1975-01-31 19.647452 24.493861 27.256874 31.036368 30.746130 1975-02-28 19.875307 25.032651 27.249036 32.252269 30.471590 1975-03-31 20.102116 25.440129 27.272794 34.035890 30.358694 1975-04-30 20.315570 25.669265 27.372090 36.222625 30.421525 1975-05-31 20.494853 25.738778 27.575029 36.457310 30.530216 1975-06-30 20.651234 25.704588 27.831925 34.815122 30.561757 1975-07-31 20.765025 25.653661 28.067595 33.585945 30.461846 1975-08-31 20.773227 25.634210 28.270963 33.012826 30.219990 1975-09-30 20.706608 25.658333 28.441906 32.878150 29.872967 1975-10-31 20.688197 25.734995 28.557490 33.009574 29.587931 1975-11-30 20.814759 25.905826 28.632126 33.263831 29.500462 1975-12-31 21.038689 26.135594 28.689278 33.409853 29.556919 1976-01-31 21.255645 26.342346 28.718473 33.373301 29.646579 1976-02-29 21.438718 26.490259 28.720166 33.389839 29.668915 1976-03-31 21.621099 26.584399 28.727504 33.932085 29.632195 1976-04-30 21.792312 26.656375 28.791011 35.154826 29.671058 1976-05-31 21.909956 26.734638 28.885535 35.487947 29.878039 1976-06-30 21.979575 26.855000 28.940313 34.629923 30.283138 1976-07-31 22.009310 27.025475 28.944659 34.033513 30.734291 1976-08-31 22.008362 27.166350 28.919844 33.921707 30.973968 1976-09-30 22.032409 27.239081 28.893143 34.027834 31.028048 1976-10-31 22.173065 27.324569 28.909225 34.133866 30.981488 1976-11-30 22.440542 27.393190 29.007428 34.200512 30.881753 1976-12-31 22.721354 27.354598 29.182626 34.061910 30.811641 1977-01-31 22.933155 27.275330 29.402921 33.577663 30.784891 1977-02-28 23.109582 27.246175 29.620419 32.890087 30.822328 1977-03-31 23.307137 27.324545 29.773347 33.012283 30.925928 1977-04-30 23.577776 27.621353 29.833276 34.777339 31.088212 1977-05-31 23.916893 28.112667 29.825291 35.992038 31.285932 1977-06-30 24.314146 28.656180 29.812207 35.536988 31.499936 ... ... ... ... ... ... 2015-01-31 144.167659 128.930628 147.539868 156.288395 115.926268 2015-02-28 146.284656 128.731928 147.499368 158.026599 116.940183 2015-03-31 148.787298 129.501519 148.110160 160.022443 118.515241 2015-04-30 151.226946 131.103544 149.408683 161.889730 120.267075 2015-05-31 153.509348 132.981211 150.877619 164.167326 121.714831 2015-06-30 155.288726 134.466828 151.743217 166.451645 122.729749 2015-07-31 156.425206 135.065680 151.843141 168.120303 123.278571 2015-08-31 156.888998 134.488097 151.741030 169.009810 123.587220 2015-09-30 157.064733 133.132658 151.850814 169.732543 123.898885 2015-10-31 157.190599 131.961233 152.312323 170.843980 124.145452 2015-11-30 157.048440 131.161984 152.985548 171.812399 124.174661 2015-12-31 157.307790 130.343517 153.464272 172.210638 124.276509 2016-01-31 158.660182 129.648250 153.649657 172.643866 124.613819 2016-02-29 160.952065 129.513436 153.718342 174.353115 125.323799 2016-03-31 163.899156 130.110334 153.939635 177.187484 126.762679 2016-04-30 166.958739 131.412487 154.417719 179.602582 128.884442 2016-05-31 169.664346 132.903451 154.884881 181.562912 130.801806 2016-06-30 171.581083 134.087932 155.215671 183.548631 131.902469 2016-07-31 172.648655 134.552888 155.376120 185.128708 132.516847 2016-08-31 173.086107 134.030144 155.206991 186.414106 132.691453 2016-09-30 173.227900 133.270077 154.710212 187.430137 132.674728 2016-10-31 173.385423 132.789329 154.082988 188.299249 132.747039 2016-11-30 173.566781 132.353426 153.524609 189.018972 132.740394 2016-12-31 174.341632 131.808821 152.978762 189.844825 132.738755 2017-01-31 176.120468 131.291994 152.649917 191.190460 133.094885 2017-02-28 178.562359 131.116584 152.963522 192.906654 134.047852 2017-03-31 181.220486 131.925410 154.149283 194.836579 135.683034 2017-04-30 183.680417 133.951730 155.887776 196.925531 137.823245 2017-05-31 186.187747 136.547673 157.638196 198.450983 139.670085 2017-06-30 187.976054 138.524640 159.252241 199.987057 140.914383 ... SD TN TX UT \Date ... 1975-01-31 ... 37.754067 32.171503 32.626112 24.593496 1975-02-28 ... 37.337158 32.222504 32.958338 24.947068 1975-03-31 ... 36.912611 32.312085 33.546541 25.262533 1975-04-30 ... 36.489475 32.439126 34.398979 25.510183 1975-05-31 ... 36.102422 32.585102 34.651415 25.671483 1975-06-30 ... 35.806520 32.744740 34.222331 25.718573 1975-07-31 ... 35.610109 32.911205 33.930958 25.658370 1975-08-31 ... 35.463960 33.086491 33.890084 25.570250 1975-09-30 ... 35.342593 33.315025 33.965869 25.551407 1975-10-31 ... 35.262108 33.656965 34.082889 25.716519 1975-11-30 ... 35.246260 34.109196 34.303998 26.077244 1975-12-31 ... 35.319802 34.516641 34.509390 26.473878 1976-01-31 ... 35.499957 34.707167 34.643401 26.824573 1976-02-29 ... 35.790652 34.681294 34.952800 27.156097 1976-03-31 ... 36.161829 34.597537 35.688706 27.459836 1976-04-30 ... 36.556026 34.624454 36.720822 27.732824 1976-05-31 ... 36.933173 34.719060 37.037879 27.951893 1976-06-30 ... 37.273964 34.745390 36.642609 28.087228 1976-07-31 ... 37.592575 34.741913 36.446191 28.223297 1976-08-31 ... 37.888156 34.794782 36.453791 28.396717 1976-09-30 ... 38.100695 34.894346 36.552274 28.539690 1976-10-31 ... 38.172081 35.002671 36.765258 28.673632 1976-11-30 ... 38.119135 35.105316 37.070697 28.881504 1976-12-31 ... 38.038400 35.235608 37.279759 29.193845 1977-01-31 ... 38.013313 35.454168 37.445796 29.548910 1977-02-28 ... 38.081055 35.792957 37.882246 29.907678 1977-03-31 ... 38.276353 36.224945 38.933838 30.304096 1977-04-30 ... 38.647993 36.688615 40.603675 30.756327 1977-05-31 ... 39.199588 37.123652 40.913325 31.233794 1977-06-30 ... 39.866278 37.551632 39.924533 31.699209 ... ... ... ... ... ... 2015-01-31 ... 150.388726 133.871790 156.835154 147.177031 2015-02-28 ... 151.110585 134.620494 158.017454 148.588786 2015-03-31 ... 152.333628 135.857941 159.871952 150.441126 2015-04-30 ... 153.697091 137.325002 161.755716 152.320416 2015-05-31 ... 154.904534 138.881299 163.527696 154.033833 2015-06-30 ... 155.872554 140.135567 165.243458 155.323979 2015-07-31 ... 156.579706 140.816036 166.371662 156.134630 2015-08-31 ... 157.007037 141.180401 166.542478 156.695655 2015-09-30 ... 157.303222 141.501492 166.665983 157.220849 2015-10-31 ... 157.629249 141.716678 167.182878 157.736346 2015-11-30 ... 157.893027 141.642814 167.494674 158.065307 2015-12-31 ... 158.159982 141.427437 167.532281 158.416922 2016-01-31 ... 158.494928 141.547459 168.158064 159.146505 2016-02-29 ... 158.822537 142.264027 169.810792 160.198260 2016-03-31 ... 159.279722 143.658095 171.539418 161.820369 2016-04-30 ... 160.045885 145.600353 173.256735 164.246382 2016-05-31 ... 161.268283 147.363228 175.303755 166.563808 2016-06-30 ... 162.843363 148.476246 176.800415 168.133279 2016-07-31 ... 164.253934 149.491748 177.724614 169.366037 2016-08-31 ... 165.176550 150.669847 178.572709 170.199149 2016-09-30 ... 165.446796 151.391978 179.165056 170.459830 2016-10-31 ... 164.878105 151.439237 179.267350 170.234772 2016-11-30 ... 163.777107 151.329018 179.011867 169.817316 2016-12-31 ... 162.867985 151.241392 178.993963 169.848764 2017-01-31 ... 162.658626 151.575136 180.056846 170.985925 2017-02-28 ... 163.232106 152.857818 181.843074 173.282842 2017-03-31 ... 164.585344 154.599873 183.832887 175.951227 2017-04-30 ... 166.576154 156.280502 186.446220 178.208219 2017-05-31 ... 168.838073 157.697551 188.999583 180.104079 2017-06-30 ... 170.881416 158.797167 191.145051 181.469212 VT VA WA WV WI \Date 1975-01-31 26.620695 27.901501 17.478975 41.006639 28.115545 1975-02-28 26.937920 28.192244 17.544439 42.051072 28.490112 1975-03-31 27.244899 28.407625 17.652704 43.139021 28.861735 1975-04-30 27.525197 28.570828 17.785996 44.260809 29.197658 1975-05-31 27.771740 28.712080 17.910147 45.388703 29.476274 1975-06-30 27.990373 28.850736 18.042067 46.463410 29.691981 1975-07-31 28.170273 29.044530 18.187802 47.405677 29.860880 1975-08-31 28.289204 29.242400 18.277487 48.156768 30.009379 1975-09-30 28.350415 29.305152 18.284039 48.659907 30.201191 1975-10-31 28.372390 29.251568 18.300061 48.881559 30.423250 1975-11-30 28.367012 29.157374 18.431764 48.888419 30.572815 1975-12-31 28.339887 29.052615 18.647899 48.790877 30.626502 1976-01-31 28.294290 28.973904 18.867923 48.673086 30.633439 1976-02-29 28.239803 29.018855 19.090844 48.618452 30.625383 1976-03-31 28.206607 29.201592 19.304640 48.656525 30.648633 1976-04-30 28.239656 29.429079 19.498190 48.730556 30.769416 1976-05-31 28.355536 29.674373 19.721004 48.779634 30.982752 1976-06-30 28.545312 29.887655 20.029470 48.776707 31.182373 1976-07-31 28.791784 30.027575 20.423411 48.719739 31.339649 1976-08-31 29.064077 30.185942 20.767478 48.642864 31.521193 1976-09-30 29.326231 30.349356 20.963020 48.596298 31.735860 1976-10-31 29.551156 30.464092 21.092221 48.598991 31.944387 1976-11-30 29.735081 30.579152 21.269940 48.663287 32.191967 1976-12-31 29.890396 30.677420 21.482062 48.821202 32.515778 1977-01-31 30.027569 30.760146 21.641866 49.098619 32.878675 1977-02-28 30.155120 30.894382 21.809690 49.481909 33.304425 1977-03-31 30.296011 31.101357 22.125344 49.947511 33.800142 1977-04-30 30.475071 31.348194 22.626472 50.489419 34.284364 1977-05-31 30.705529 31.639371 23.173477 51.049705 34.757529 1977-06-30 30.983867 31.975911 23.670298 51.554349 35.339741 ... ... ... ... ... ... 2015-01-31 157.202112 168.439563 158.042651 139.866172 119.615921 2015-02-28 157.829665 168.541470 159.704842 140.318073 120.092465 2015-03-31 159.273148 169.861735 162.428411 141.519823 121.304395 2015-04-30 161.503688 171.801426 165.417879 143.100354 122.966455 2015-05-31 164.034173 173.639545 167.971869 144.401776 124.927943 2015-06-30 166.033178 174.892157 169.997388 144.945682 126.399787 2015-07-31 166.989955 175.245914 171.581229 144.803141 126.930033 2015-08-31 166.987853 175.114416 172.529522 144.262970 126.933873 2015-09-30 166.365554 174.926488 173.013062 143.524402 126.693759 2015-10-31 165.411259 174.427615 173.652159 142.768395 126.501600 2015-11-30 164.372868 173.579427 174.400987 142.013520 126.301044 2015-12-31 163.504043 172.667656 174.984247 141.263657 125.644494 2016-01-31 162.980355 172.392378 176.124979 140.651142 125.102488 2016-02-29 162.866811 173.490777 178.702477 140.422218 125.615208 2016-03-31 163.246502 175.613691 182.006211 140.841035 127.139877 2016-04-30 164.265165 177.779940 185.190232 141.916831 129.057519 2016-05-31 165.625447 179.683737 187.972140 143.353606 131.047203 2016-06-30 166.942471 180.955316 190.151484 144.612754 132.929595 2016-07-31 167.977912 181.180301 191.792737 145.294723 134.119353 2016-08-31 168.369397 180.926844 192.769997 145.610239 134.413904 2016-09-30 167.972407 180.569133 193.033028 145.875422 134.177277 2016-10-31 167.141612 180.221308 193.034111 145.997822 133.865722 2016-11-30 166.394126 179.609332 193.448931 145.886340 133.160883 2016-12-31 166.015309 178.774034 194.611201 145.429858 132.251746 2017-01-31 166.192565 178.502466 196.443039 144.782388 132.037674 2017-02-28 166.949802 179.613711 199.582264 144.429322 132.606904 2017-03-31 168.049096 182.286286 204.224082 144.741636 134.149181 2017-04-30 169.410542 185.296871 208.884908 145.748552 136.579530 2017-05-31 171.178579 187.538848 212.810431 147.107015 138.864252 2017-06-30 172.565476 189.396040 216.341550 148.077932 140.898320 WY Date 1975-01-31 31.663002 1975-02-28 32.157887 1975-03-31 32.678700 1975-04-30 33.211169 1975-05-31 33.718382 1975-06-30 34.186630 1975-07-31 34.620016 1975-08-31 35.007426 1975-09-30 35.333703 1975-10-31 35.573043 1975-11-30 35.729397 1975-12-31 35.833804 1976-01-31 35.922171 1976-02-29 36.042615 1976-03-31 36.223635 1976-04-30 36.469061 1976-05-31 36.799338 1976-06-30 37.255128 1976-07-31 37.824382 1976-08-31 38.429590 1976-09-30 39.036745 1976-10-31 39.655906 1976-11-30 40.240983 1976-12-31 40.715412 1977-01-31 41.084114 1977-02-28 41.411241 1977-03-31 41.735093 1977-04-30 42.069710 1977-05-31 42.442851 1977-06-30 42.921568 ... ... 2015-01-31 180.064988 2015-02-28 180.356737 2015-03-31 181.067914 2015-04-30 182.365664 2015-05-31 184.081078 2015-06-30 185.850321 2015-07-31 187.127244 2015-08-31 187.440939 2015-09-30 186.909502 2015-10-31 185.912710 2015-11-30 184.709911 2015-12-31 183.679069 2016-01-31 183.194830 2016-02-29 183.401656 2016-03-31 184.247241 2016-04-30 185.442763 2016-05-31 186.526314 2016-06-30 187.348829 2016-07-31 187.997204 2016-08-31 188.463676 2016-09-30 188.474232 2016-10-31 187.790452 2016-11-30 186.767554 2016-12-31 185.988855 2017-01-31 185.784342 2017-02-28 186.212775 2017-03-31 187.118813 2017-04-30 188.385079 2017-05-31 189.901394 2017-06-30 191.424312 [510 rows x 50 columns]
7、Percent Change - Data Analysis with Python and Pandas Tutorial
import quandlimport pandas as pdimport pickle# Not necessary, I just do this so I do not show my API key.#api_key = open('quandlapikey.txt','r').read()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_data(): states = state_list() main_df = pd.DataFrame() for abbv in states: query = "FMAC/HPI_"+str(abbv) df = Quandl.get(query, authtoken='n75cJa9b8mNzuVz65S1S') print(query) if main_df.empty: main_df = df else: main_df = main_df.join(df) pickle_out = open('fiddy_states.pickle','wb') pickle.dump(main_df, pickle_out) pickle_out.close() HPI_data = pd.read_pickle('fiddy_states.pickle')
HPI_data['TX2'] = HPI_data['TX'] * 2print(HPI_data[['TX','TX2']].head())
TX TX2Date 1975-01-31 32.626112 65.2522241975-02-28 32.958338 65.9166771975-03-31 33.546541 67.0930831975-04-30 34.398979 68.7979581975-05-31 34.651415 69.302830
import matplotlib.pyplot as pltfrom matplotlib import stylestyle.use('fivethirtyeight')fig = plt.figure(figsize = (10,8))#HPI_data[['TX','TX2']].plot()HPI_data.plot()plt.legend().remove()plt.show()
<matplotlib.figure.Figure at 0x20b95125ac8>
def grab_initial_state_data(): states = state_list() main_df = pd.DataFrame() for abbv in states: query = "FMAC/HPI_"+str(abbv) df = quandl.get(query, authtoken='n75cJa9b8mNzuVz65S1S') df.columns = [str(abbv)] print(query) df = df.pct_change() print(df.head()) if main_df.empty: main_df = df else: main_df = main_df.join(df) pickle_out = open('fiddy_states2.pickle','wb') pickle.dump(main_df, pickle_out) pickle_out.close()grab_initial_state_data()
FMAC/HPI_AL ALDate 1975-01-31 NaN1975-02-28 0.0060161975-03-31 0.0069621975-04-30 0.0083811975-05-31 0.007693FMAC/HPI_AK AKDate 1975-01-31 NaN1975-02-28 0.0152591975-03-31 0.0153621975-04-30 0.0156621975-05-31 0.016596FMAC/HPI_AZ AZDate 1975-01-31 NaN1975-02-28 0.0185021975-03-31 0.0171151975-04-30 0.0130901975-05-31 0.006746FMAC/HPI_AR ARDate 1975-01-31 NaN1975-02-28 0.0092291975-03-31 0.0079771975-04-30 0.0063971975-05-31 0.005974FMAC/HPI_CA CADate 1975-01-31 NaN1975-02-28 0.0032401975-03-31 0.0120271975-04-30 0.0196081975-05-31 0.016021FMAC/HPI_CO CODate 1975-01-31 NaN1975-02-28 0.0115971975-03-31 0.0114121975-04-30 0.0106191975-05-31 0.008825FMAC/HPI_CT CTDate 1975-01-31 NaN1975-02-28 0.0219971975-03-31 0.0162781975-04-30 0.0090071975-05-31 0.002708FMAC/HPI_DE DEDate 1975-01-31 NaN1975-02-28 -0.0002881975-03-31 0.0008721975-04-30 0.0036411975-05-31 0.007414FMAC/HPI_FL FLDate 1975-01-31 NaN1975-02-28 0.0391771975-03-31 0.0553021975-04-30 0.0642481975-05-31 0.006479FMAC/HPI_GA GADate 1975-01-31 NaN1975-02-28 -0.0089291975-03-31 -0.0037051975-04-30 0.0020701975-05-31 0.003573FMAC/HPI_HI HIDate 1975-01-31 NaN1975-02-28 -0.0023341975-03-31 -0.0005421975-04-30 0.0021631975-05-31 0.004587FMAC/HPI_ID IDDate 1975-01-31 NaN1975-02-28 -0.0015621975-03-31 -0.0016861975-04-30 -0.0013121975-05-31 -0.000153FMAC/HPI_IL ILDate 1975-01-31 NaN1975-02-28 0.0087451975-03-31 0.0108461975-04-30 0.0112691975-05-31 0.006466FMAC/HPI_IN INDate 1975-01-31 NaN1975-02-28 0.0138641975-03-31 0.0132721975-04-30 0.0105201975-05-31 0.006104FMAC/HPI_IA IADate 1975-01-31 NaN1975-02-28 0.0165491975-03-31 0.0147441975-04-30 0.0113251975-05-31 0.006970FMAC/HPI_KS KSDate 1975-01-31 NaN1975-02-28 0.0112511975-03-31 0.0123011975-04-30 0.0126651975-05-31 0.011942FMAC/HPI_KY KYDate 1975-01-31 NaN1975-02-28 0.0013041975-03-31 0.0009161975-04-30 0.0022061975-05-31 0.006560FMAC/HPI_LA LADate 1975-01-31 NaN1975-02-28 0.0188591975-03-31 0.0186501975-04-30 0.0139501975-05-31 0.006747FMAC/HPI_ME MEDate 1975-01-31 NaN1975-02-28 -0.0044401975-03-31 -0.0032151975-04-30 -0.0011591975-05-31 0.001580FMAC/HPI_MD MDDate 1975-01-31 NaN1975-02-28 -0.0031741975-03-31 -0.0015801975-04-30 0.0015691975-05-31 0.004433FMAC/HPI_MA MADate 1975-01-31 NaN1975-02-28 -0.0063751975-03-31 -0.0064771975-04-30 -0.0052261975-05-31 -0.002419FMAC/HPI_MI MIDate 1975-01-31 NaN1975-02-28 0.0147491975-03-31 0.0118251975-04-30 0.0071371975-05-31 0.001966FMAC/HPI_MN MNDate 1975-01-31 NaN1975-02-28 0.0100081975-03-31 0.0085421975-04-30 0.0079541975-05-31 0.009405FMAC/HPI_MS MSDate 1975-01-31 NaN1975-02-28 -0.0067331975-03-31 -0.0048861975-04-30 -0.0018081975-05-31 0.001422FMAC/HPI_MO MODate 1975-01-31 NaN1975-02-28 0.0444451975-03-31 0.0430231975-04-30 0.0335101975-05-31 -0.001747FMAC/HPI_MT MTDate 1975-01-31 NaN1975-02-28 0.0117101975-03-31 0.0123101975-04-30 0.0125101975-05-31 0.011463FMAC/HPI_NE NEDate 1975-01-31 NaN1975-02-28 -0.0004531975-03-31 -0.0005961975-04-30 -0.0006561975-05-31 -0.000797FMAC/HPI_NV NVDate 1975-01-31 NaN1975-02-28 0.0170141975-03-31 0.0161491975-04-30 0.0147341975-05-31 0.012890FMAC/HPI_NH NHDate 1975-01-31 NaN1975-02-28 0.0155091975-03-31 0.0139901975-04-30 0.0114411975-05-31 0.007990FMAC/HPI_NJ NJDate 1975-01-31 NaN1975-02-28 -0.0226661975-03-31 -0.0135971975-04-30 -0.0010441975-05-31 0.007732FMAC/HPI_NM NMDate 1975-01-31 NaN1975-02-28 0.0149421975-03-31 0.0139651975-04-30 0.0111681975-05-31 0.008234FMAC/HPI_NY NYDate 1975-01-31 NaN1975-02-28 -0.0199261975-03-31 -0.0089921975-04-30 0.0002671975-05-31 0.005756FMAC/HPI_NC NCDate 1975-01-31 NaN1975-02-28 0.0102351975-03-31 0.0088621975-04-30 0.0077321975-05-31 0.006536FMAC/HPI_ND NDDate 1975-01-31 NaN1975-02-28 -0.0026251975-03-31 -0.0013751975-04-30 0.0016121975-05-31 0.005081FMAC/HPI_OH OHDate 1975-01-31 NaN1975-02-28 0.0017691975-03-31 0.0055531975-04-30 0.0074471975-05-31 0.007754FMAC/HPI_OK OKDate 1975-01-31 NaN1975-02-28 -0.0031201975-03-31 -0.0017541975-04-30 -0.0011641975-05-31 -0.000813FMAC/HPI_OR ORDate 1975-01-31 NaN1975-02-28 0.0246581975-03-31 0.0228211975-04-30 0.0201911975-05-31 0.018966FMAC/HPI_PA PADate 1975-01-31 NaN1975-02-28 0.0122331975-03-31 0.0095571975-04-30 0.0071801975-05-31 0.008169FMAC/HPI_RI RIDate 1975-01-31 NaN1975-02-28 0.0208061975-03-31 0.0206041975-04-30 0.0203201975-05-31 0.019339FMAC/HPI_SC SCDate 1975-01-31 NaN1975-02-28 0.0122501975-03-31 0.0089681975-04-30 0.0048261975-05-31 0.002914FMAC/HPI_SD SDDate 1975-01-31 NaN1975-02-28 -0.0110431975-03-31 -0.0113711975-04-30 -0.0114631975-05-31 -0.010607FMAC/HPI_TN TNDate 1975-01-31 NaN1975-02-28 0.0015851975-03-31 0.0027801975-04-30 0.0039321975-05-31 0.004500FMAC/HPI_TX TXDate 1975-01-31 NaN1975-02-28 0.0101831975-03-31 0.0178471975-04-30 0.0254111975-05-31 0.007338FMAC/HPI_UT UTDate 1975-01-31 NaN1975-02-28 0.0143771975-03-31 0.0126451975-04-30 0.0098031975-05-31 0.006323FMAC/HPI_VT VTDate 1975-01-31 NaN1975-02-28 0.0119161975-03-31 0.0113961975-04-30 0.0102881975-05-31 0.008957FMAC/HPI_VA VADate 1975-01-31 NaN1975-02-28 0.0104201975-03-31 0.0076401975-04-30 0.0057451975-05-31 0.004944FMAC/HPI_WA WADate 1975-01-31 NaN1975-02-28 0.0037451975-03-31 0.0061711975-04-30 0.0075511975-05-31 0.006980FMAC/HPI_WV WVDate 1975-01-31 NaN1975-02-28 0.0254701975-03-31 0.0258721975-04-30 0.0260041975-05-31 0.025483FMAC/HPI_WI WIDate 1975-01-31 NaN1975-02-28 0.0133221975-03-31 0.0130441975-04-30 0.0116391975-05-31 0.009542FMAC/HPI_WY WYDate 1975-01-31 NaN1975-02-28 0.0156301975-03-31 0.0161951975-04-30 0.0162941975-05-31 0.015272
HPI_data = pd.read_pickle('fiddy_states2.pickle')HPI_data.plot()plt.legend().remove()plt.show()
def grab_initial_state_data(): states = state_list() main_df = pd.DataFrame() for abbv in states: query = "FMAC/HPI_"+str(abbv) df = quandl.get(query, authtoken='n75cJa9b8mNzuVz65S1S') df.columns = [str(abbv)] print(query) df[abbv] = (df[abbv]-df[abbv][0]) / df[abbv][0] * 100.0 print(df.head()) if main_df.empty: main_df = df else: main_df = main_df.join(df) pickle_out = open('fiddy_states3.pickle','wb') pickle.dump(main_df, pickle_out) pickle_out.close()grab_initial_state_data() HPI_data = pd.read_pickle('fiddy_states3.pickle')HPI_data.plot()plt.legend().remove()plt.show()
FMAC/HPI_AL ALDate 1975-01-31 0.0000001975-02-28 0.6016401975-03-31 1.3020561975-04-30 2.1510761975-05-31 2.936943FMAC/HPI_AK AKDate 1975-01-31 0.0000001975-02-28 1.5259221975-03-31 3.0855281975-04-30 4.7000441975-05-31 6.437680FMAC/HPI_AZ AZDate 1975-01-31 0.0000001975-02-28 1.8501731975-03-31 3.5933141975-04-30 4.9493621975-05-31 5.657356FMAC/HPI_AR ARDate 1975-01-31 0.0000001975-02-28 0.9228961975-03-31 1.7279451975-04-30 2.3787291975-05-31 2.990348FMAC/HPI_CA CADate 1975-01-31 0.0000001975-02-28 0.3240251975-03-31 1.5305731975-04-30 3.5213401975-05-31 5.179892FMAC/HPI_CO CODate 1975-01-31 0.0000001975-02-28 1.1597181975-03-31 2.3141121975-04-30 3.4005351975-05-31 4.313035FMAC/HPI_CT CTDate 1975-01-31 0.0000001975-02-28 2.1996951975-03-31 3.8632871975-04-30 4.7987681975-05-31 5.082566FMAC/HPI_DE DEDate 1975-01-31 0.0000001975-02-28 -0.0287571975-03-31 0.0584061975-04-30 0.4227041975-05-31 1.167247FMAC/HPI_FL FLDate 1975-01-31 0.0000001975-02-28 3.9176651975-03-31 9.6645381975-04-30 16.7102561975-05-31 17.466419FMAC/HPI_GA GADate 1975-01-31 0.0000001975-02-28 -0.8929231975-03-31 -1.2601131975-04-30 -1.0557581975-05-31 -0.702246FMAC/HPI_HI HIDate 1975-01-31 0.0000001975-02-28 -0.2334361975-03-31 -0.2875391975-04-30 -0.0718321975-05-31 0.386500FMAC/HPI_ID IDDate 1975-01-31 0.0000001975-02-28 -0.1562291975-03-31 -0.3246161975-04-30 -0.4554361975-05-31 -0.470622FMAC/HPI_IL ILDate 1975-01-31 0.0000001975-02-28 0.8744951975-03-31 1.9685411975-04-30 3.1176701975-05-31 3.784434FMAC/HPI_IN INDate 1975-01-31 0.0000001975-02-28 1.3864281975-03-31 2.7320371975-04-30 3.8127671975-05-31 4.446395FMAC/HPI_IA IADate 1975-01-31 0.0000001975-02-28 1.6548871975-03-31 3.1536911975-04-30 4.3219501975-05-31 5.049089FMAC/HPI_KS KSDate 1975-01-31 0.0000001975-02-28 1.1251231975-03-31 2.3690851975-04-30 3.6655711975-05-31 4.903573FMAC/HPI_KY KYDate 1975-01-31 0.0000001975-02-28 0.1303901975-03-31 0.2220821975-04-30 0.4431491975-05-31 1.102072FMAC/HPI_LA LADate 1975-01-31 0.0000001975-02-28 1.8859261975-03-31 3.7860531975-04-30 5.2339021975-05-31 5.943873FMAC/HPI_ME MEDate 1975-01-31 0.0000001975-02-28 -0.4439881975-03-31 -0.7640711975-04-30 -0.8790681975-05-31 -0.722483FMAC/HPI_MD MDDate 1975-01-31 0.0000001975-02-28 -0.3173891975-03-31 -0.4748861975-04-30 -0.3187711975-05-31 0.123133FMAC/HPI_MA MADate 1975-01-31 0.0000001975-02-28 -0.6374881975-03-31 -1.2810841975-04-30 -1.7970321975-05-31 -2.034558FMAC/HPI_MI MIDate 1975-01-31 0.0000001975-02-28 1.4749451975-03-31 2.6749221975-04-30 3.4076811975-05-31 3.610956FMAC/HPI_MN MNDate 1975-01-31 0.0000001975-02-28 1.0007951975-03-31 1.8635691975-04-30 2.6738101975-05-31 3.639407FMAC/HPI_MS MSDate 1975-01-31 0.0000001975-02-28 -0.6733401975-03-31 -1.1586451975-04-30 -1.3373371975-05-31 -1.197002FMAC/HPI_MO MODate 1975-01-31 0.0000001975-02-28 4.4445251975-03-31 8.9380591975-04-30 12.5886171975-05-31 12.391981FMAC/HPI_MT MTDate 1975-01-31 0.0000001975-02-28 1.1710261975-03-31 2.4164141975-04-30 3.6976231975-05-31 4.886304FMAC/HPI_NE NEDate 1975-01-31 0.0000001975-02-28 -0.0452991975-03-31 -0.1049041975-04-30 -0.1703941975-05-31 -0.250000FMAC/HPI_NV NVDate 1975-01-31 0.0000001975-02-28 1.7013791975-03-31 3.3437891975-04-30 4.8664341975-05-31 6.218143FMAC/HPI_NH NHDate 1975-01-31 0.0000001975-02-28 1.5509121975-03-31 2.9715831975-04-30 4.1496821975-05-31 4.981880FMAC/HPI_NJ NJDate 1975-01-31 0.0000001975-02-28 -2.2665861975-03-31 -3.5954791975-04-30 -3.6961531975-05-31 -2.951526FMAC/HPI_NM NMDate 1975-01-31 0.0000001975-02-28 1.4942301975-03-31 2.9116271975-04-30 4.0609941975-05-31 4.917877FMAC/HPI_NY NYDate 1975-01-31 0.0000001975-02-28 -1.9925721975-03-31 -2.8738841975-04-30 -2.8479821975-05-31 -2.288766FMAC/HPI_NC NCDate 1975-01-31 0.0000001975-02-28 1.0235181975-03-31 1.9187931975-04-30 2.7068241975-05-31 3.378153FMAC/HPI_ND NDDate 1975-01-31 0.0000001975-02-28 -0.2624711975-03-31 -0.3995641975-04-30 -0.2390491975-05-31 0.267830FMAC/HPI_OH OHDate 1975-01-31 0.0000001975-02-28 0.1768561975-03-31 0.7331771975-04-30 1.4833761975-05-31 2.270290FMAC/HPI_OK OKDate 1975-01-31 0.0000001975-02-28 -0.3120351975-03-31 -0.4868771975-04-30 -0.6027211975-05-31 -0.683515FMAC/HPI_OR ORDate 1975-01-31 0.0000001975-02-28 2.4658181975-03-31 4.8041981975-04-30 6.9202851975-05-31 8.948184FMAC/HPI_PA PADate 1975-01-31 0.0000001975-02-28 1.2233191975-03-31 2.1907221975-04-30 2.9244761975-05-31 3.765253FMAC/HPI_RI RIDate 1975-01-31 0.0000001975-02-28 2.0806011975-03-31 4.1838711975-04-30 6.3008771975-05-31 8.356600FMAC/HPI_SC SCDate 1975-01-31 0.0000001975-02-28 1.2249521975-03-31 2.1327761975-04-30 2.6256341975-05-31 2.924727FMAC/HPI_SD SDDate 1975-01-31 0.0000001975-02-28 -1.1042751975-03-31 -2.2287831975-04-30 -3.3495511975-05-31 -4.374747FMAC/HPI_TN TNDate 1975-01-31 0.0000001975-02-28 0.1585261975-03-31 0.4369771975-04-30 0.8318611975-05-31 1.285606FMAC/HPI_TX TXDate 1975-01-31 0.0000001975-02-28 1.0182841975-03-31 2.8211441975-04-30 5.4338891975-05-31 6.207614FMAC/HPI_UT UTDate 1975-01-31 0.0000001975-02-28 1.4376651975-03-31 2.7203821975-04-30 3.7273541975-05-31 4.383221FMAC/HPI_VT VTDate 1975-01-31 0.0000001975-02-28 1.1916471975-03-31 2.3448051975-04-30 3.3977371975-05-31 4.323873FMAC/HPI_VA VADate 1975-01-31 0.0000001975-02-28 1.0420321975-03-31 1.8139661975-04-30 2.3988901975-05-31 2.905144FMAC/HPI_WA WADate 1975-01-31 0.0000001975-02-28 0.3745311975-03-31 0.9939311975-04-30 1.7565131975-05-31 2.466806FMAC/HPI_WV WVDate 1975-01-31 0.0000001975-02-28 2.5469841975-03-31 5.2000891975-04-30 7.9357141975-05-31 10.686231FMAC/HPI_WI WIDate 1975-01-31 0.0000001975-02-28 1.3322401975-03-31 2.6540101975-04-30 3.8488041975-05-31 4.839774FMAC/HPI_WY WYDate 1975-01-31 0.0000001975-02-28 1.5629761975-03-31 3.2078371975-04-30 4.8895131975-05-31 6.491423
END
阅读全文
1 0
- Pandas学习总结(上)
- pandas 模块学习总结
- Pandas入门学习总结
- Python库--pandas库学习笔记总结
- pandas 学习
- Pandas学习
- pandas学习
- pandas学习笔记-丢弃指定轴上的项
- Pandas学习笔记:pandas基础
- Pandas入门(上)
- pandas入门(上)
- pandas-series总结
- pandas易错点总结
- pandas的问题总结
- pandas学习笔记(1)--pandas简介
- Pandas学习笔记一(Pandas数据结构)
- pandas学习(三)
- pandas 学习笔记
- Android apk 加固
- 线程阻塞怎么结束
- C++ 快排
- java的path与classpath
- Mysql笔记
- Pandas学习总结(上)
- 常见类---BigDecimal类
- 设计模式之单例模式
- (noip 模拟 染色)<树形DP>
- Prime Factors
- nspr线程相关
- opencv读取txt文件,并赋值为Mat矩阵
- ELF文件加密相关
- Java设计模式--原型模式【Prototype Pattern】