Python 3.x Python3使用起始值作为最终值的平均值进行外推

Python 3.x Python3使用起始值作为最终值的平均值进行外推,python-3.x,sas,interpolation,extrapolation,Python 3.x,Sas,Interpolation,Extrapolation,我有一个数据框,里面有一些年度数据,我想将其外推到每月。我有一个在SAS中运行的进程,我正在迁移到Python3,它完成了这项工作。它取年值作为全年的平均值,将月值分散开来(第6个月基本上是该值) 以下是SAS代码: proc expand data = interpolation out = interpolate1 from = year to =month; id MDY; convert WW_UnempRateFC / observed = average; convert US_ga

我有一个数据框,里面有一些年度数据,我想将其外推到每月。我有一个在SAS中运行的进程,我正在迁移到Python3,它完成了这项工作。它取年值作为全年的平均值,将月值分散开来(第6个月基本上是该值)

以下是SAS代码:

proc expand data = interpolation out = interpolate1 from = year to =month;
id MDY;
convert WW_UnempRateFC / observed = average;
convert US_gas/observed = average;
run;
以下是起始数据

   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    
以下是一年的SAS输出:

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
以下是我到目前为止在Python中的内容。我已经创建了datetime列并将其移动到索引中,以便.interpolate工作。然而,无论我尝试哪种方法(线性、样条等),我都无法获得相同的输出

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()
第二部分是一些操作数据以获得不同结果的失败尝试。例如,将值移动到特定月份,然后从该月份开始线性扩展

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)

我真的在网上找不到任何关于如何推断类似于SAS方法的数字的东西,请帮助

您是否有权访问proc expand?(ETL包,如果我没记错的话。)是的,这有什么帮助?您是否有权访问proc expand?(ETL包,如果我没记错的话。)是的,这有什么帮助?