2017-11-02 16 views
0

パンダで時間の経過にしたがって補間するのに問題がありますので、非常に基本的な例に戻しました。パンダ時間補間 - NaNs

Cインデックス(datetime64アレイ)であり、データフレームであり、Bは

In [104]: c 
Out[104]: 
       b 
a      
2009-04-01 386.928680 
2009-06-01 386.502686 

In [105]: a 
Out[105]: 
0 2009-04-01 
1 2009-06-01 
dtype: datetime64[ns] 

In [106]: b 
Out[106]: 
0 386.928680 
1 386.502686 
dtype: float64 

upsampled = c.resample('M') 
interpolated = upsampled.interpolate(method='linear') 

In [107]: interpolated 
Out[107]: 
     b 
a    
2009-04-30 NaN 
2009-05-31 NaN 
2009-06-30 NaN 

Iは補間方法を変更し、制限キーワードだけを設定しようとした(float配列)データであります助けてくれると思われ、すべてのNaNを取得するだけです。

答えて

3

元の値を取得するには、サンプルを 'MS'月に変更する必要があります。

c.resample('MS').asfreq().interpolate(method='linear') 

出力:

     b 
a      
2009-04-01 386.928680 
2009-05-01 386.715683 
2009-06-01 386.502686