python - Pandas prepend data to multi-indexed series -


i have following pandas.series object following data:

country        year united states  2004     416.205383                2005     430.326178                2006     444.208260                2007     456.880067                2009     472.733367                2008     474.420151                2010     480.486400                2011     495.654594                2012     505.911360                2013     513.322114 name: fp.cpi.totl, dtype: float64 

let's call cpi. i'd prepend year 2014 series, instead use string name 'ttm'.

cpi.index

multiindex(levels=[[u'united states'], [u'2004', u'2005', u'2006', u'2007', u'2008', u'2009', u'2010', u'2011', u'2012', u'2013']],            labels=[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 3, 5, 4, 6, 7, 8, 9]],            names=[u'country', u'year']) 

and cpi.values

array([  416.20538282,   430.32617782,   444.20825976,   456.88006655,          472.73336741,   474.42015054,   480.4864    ,   495.65459441,          505.91135964,   513.32211444,  1000.        ]) 

i tried

row = pd.series(100,index=['ttm']) cpi.append(row) 

but appends wrong level within multiindex. here, construct new array of values, new multiindex, , new dataframe, seems pretty wasteful. there easier way?


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -