python 3.x - Python3 extrapolate using the starting value as the average of the final values -


i have dataframe yearly data in want extrapolate monthly. had process ran in sas, moving python3, did this. took yearly value , used average full year, spreading out monthly values (with month 6 being value).

here sas code:

proc expand data = interpolation out = interpolate1 = year =month; id mdy; convert ww_unempratefc / observed = average; convert us_gas/observed = average; run; 

below starting data.

   year  rw_unempfc usgas    0   2011    7.49    3.40     1   2012    7.30    3.54     2   2013    7.10    3.33     3   2014    7.00    2.90     4   2015    6.90    2.21     

here sas output 1 year:

jan2011 7.5054662504    3.1396263397 feb2011 7.5116185928    3.2054411594 mar2011 7.5147516515    3.2648661888 apr2011 7.515085202     3.3200225579 may2011 7.512602436     3.3689424153 jun2011 7.5075223604    3.4119533453 jul2011 7.5000068984    3.4492530654 aug2011 7.4900880953    3.4816285652 sep2011 7.4782763777    3.5082981244 oct2011 7.464603791     3.5300487326 nov2011 7.4492789568    3.5471936524 dec2011 7.4324741835    3.5599449231 

here have far in python. i've created datetime column , moved index .interpolate work. however, no matter method try (linear,spline, etc) can't same output.

interpolation['date'] = interpolation['year'].astype(str).apply(lambda x:  pd.to_datetime(x, format='%y')) interpolation = interpolation.set_index(['date']) interpolationexp = interpolation.resample('m').mean().reset_index() interpolationexp = interpolationexp.interpolate() 

this second part failed attempts manipulate data different. moving value specific month , expanding linearly there.

interpolationexp['year'] = interpolationexp['year'].apply(np.floor) interpolation2 = interpolationexp.merge(interpolation, on='year') interpolation2['usgas_y'] = np.where(interpolation2['date'].month==6,  interpolation2['usgas_y'], '') interpolation2.head(20) 

i can't find else online on how extrapolate numbers similar sas method, please help!


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -