2017-07-15 11 views
1

を提示するパンダのdatetimeインデックスを拡張:は、私は、次のインデックスを持つパンダのデータフレームを持っている日付

DatetimeIndex(['2013-04-16', '2013-04-17', '2013-04-18', '2013-04-19', 
       '2013-04-20', '2013-04-21', '2013-04-22', '2013-04-23', 
       '2013-04-24', '2013-04-25', 
       ... 
       '2017-07-03', '2017-07-04', '2017-07-05', '2017-07-06', 
       '2017-07-07', '2017-07-08', '2017-07-09', '2017-07-10', 
       '2017-07-11', '2017-07-12'], 
       dtype='datetime64[ns]', length=406, freq=None) 

は、どのように私は、このインデックスは、すなわち2017年7月15日の日付を提示するために拡張することができますか?

あなたが indexdate_rangemax値で Index.unionを使用することができます

答えて

1

idx = pd.DatetimeIndex(['2017-07-07', '2017-07-08', '2017-07-09', '2017-07-10', 
         '2017-07-11', '2017-07-12']) 

idx = pd.date_range(idx.max(),pd.datetime.today()).union(idx) 
print (idx) 
DatetimeIndex(['2017-07-07', '2017-07-08', '2017-07-09', '2017-07-10', 
       '2017-07-11', '2017-07-12', '2017-07-13', '2017-07-14', 
       '2017-07-15'], 
       dtype='datetime64[ns]', freq='D') 

それとも[-1]で最後の値を選択します。

idx = pd.date_range(idx[-1],pd.datetime.today()).union(idx) 
print (idx) 
DatetimeIndex(['2017-07-07', '2017-07-08', '2017-07-09', '2017-07-10', 
       '2017-07-11', '2017-07-12', '2017-07-13', '2017-07-14', 
       '2017-07-15'], 
       dtype='datetime64[ns]', freq='D') 
+0

感謝!この作品 – user308827

関連する問題